Programming Tips - PHP: split a UTF-8 string into characters

Date: 2017sep15 Language: php Q. PHP: split a UTF-8 string into characters A.
// Split a UTF-8 string to characters function utf8Split($str) { return preg_split('//u', $str, null, PREG_SPLIT_NO_EMPTY); } // See if a string has accented letters or other non-ASCII chars function hasMultibyteChars($str) { $charArray = utf8Split($str) { $len = count($charArray); for ($i = 0; $i < $len; $i++) { $char = $charArray[$i]; if (strlen($char) > 1) return true; } return false; }
This is better than using the multibyte functions. Don't forget to add
<meta charset="UTF-8">
to your page.