Skip to content

Instantly share code, notes, and snippets.

@blessdyb
Created September 13, 2016 06:41
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blessdyb/2b2f31a24e34f2c8da3733d49863c750 to your computer and use it in GitHub Desktop.
Save blessdyb/2b2f31a24e34f2c8da3733d49863c750 to your computer and use it in GitHub Desktop.
PHP unserialize utf8 fix
<?php
/**
* Mulit-byte Unserialize (http://stackoverflow.com/questions/2853454/php-unserialize-fails-with-non-encoded-characters)
*
* UTF-8 will screw up a serialized string
*
* @access private
* @param string
* @return string
*/
function mb_unserialize($string) {
$string = preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'", $string);
return unserialize($string);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment