Skip to content

Instantly share code, notes, and snippets.

@man4toman
Last active July 31, 2019 08:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save man4toman/029f43b802f4ee52d5fab2526cdd3cbd to your computer and use it in GitHub Desktop.
Save man4toman/029f43b802f4ee52d5fab2526cdd3cbd to your computer and use it in GitHub Desktop.
Mixed encoding and make everything UTF-8
<?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