Created
June 24, 2016 17:18
-
-
Save max-dark/238f444155667a466898ef92796769cb to your computer and use it in GitHub Desktop.
tools for utf-8 strings
This file contains 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 | |
/** | |
* split utf-8 string to array of chars | |
* @param string $str | |
* @return array | |
*/ | |
function chars_of($str) { | |
return preg_split('/(?<!^)(?!$)/u', $str); | |
} | |
/** | |
* utf-8 analog for strtr function | |
* @param string $str | |
* @param string $from | |
* @param string $to | |
* @return string | |
*/ | |
function mb_strtr($str, $from, $to) { | |
return strtr( | |
$str, | |
array_combine( | |
chars_of($from), | |
chars_of($to) | |
) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment