Skip to content

Instantly share code, notes, and snippets.

@yeungon
Created December 5, 2017 01:22
Show Gist options
  • Save yeungon/1fd4d754f72b0f21a6d25a984010096e to your computer and use it in GitHub Desktop.
Save yeungon/1fd4d754f72b0f21a6d25a984010096e to your computer and use it in GitHub Desktop.
split unicode/vietnamese string
function str_split_unicode($str, $l = 0) {
if ($l > 0) {
$ret = array();
$len = mb_strlen($str, "UTF-8");
for ($i = 0; $i < $len; $i += $l) {
$ret[] = mb_substr($str, $i, $l, "UTF-8");
}
return $ret;
}
// hàm preg_split thuộc nhóm xử lý text bằng REGEX http://php.net/manual/en/ref.pcre.php
return preg_split("//u", $str, -1, PREG_SPLIT_NO_EMPTY);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment