Last active
July 31, 2019 08:47
-
-
Save man4toman/029f43b802f4ee52d5fab2526cdd3cbd to your computer and use it in GitHub Desktop.
Mixed encoding and make everything UTF-8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* @exampple: echo utf_correction('Ù…ØØªÙˆØ§ÛŒ میکس شده و بخش سالم'); | |
* @link: https://stackoverflow.com/questions/48948340/mixed-encoding-and-make-everything-utf-8 | |
**/ | |
function utf_correction(''){ | |
$str_hex = bin2hex($str); | |
$str = hex2bin($str_hex); | |
$fixed = preg_replace_callback( | |
'/\\P{Arabic}+/u', | |
function (array $m) { return iconv('UTF-8', 'ISO-8859-1', $m[0]); }, | |
$str | |
); | |
return $fixed; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment