Skip to content

Instantly share code, notes, and snippets.

@max-dark
Created June 24, 2016 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save max-dark/238f444155667a466898ef92796769cb to your computer and use it in GitHub Desktop.
Save max-dark/238f444155667a466898ef92796769cb to your computer and use it in GitHub Desktop.
tools for utf-8 strings
<?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