Created
January 13, 2012 22:28
-
-
Save elinw/1609111 to your computer and use it in GitHub Desktop.
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
if ($lang === 'jp') | |
{ | |
// Iterate through the terms and test if they contain Chinese. | |
for ($i = 0, $n = count($terms); $i < $n; $i++) | |
{ | |
$charMatches = array(); | |
$charCount = preg_match_all('#[\x{4E00}-\x{9FBF}]#mui', $terms[$i], $charMatches); | |
$charCount += preg_match_all('#[\x{3040–\x{309F}]#mui', $terms[$i], $charMatches); | |
$charCount += preg_match_all('#[\x{30A0}-\x{30FF}]#mui', $terms[$i], $charMatches); | |
// Split apart any groups of Chinese characters. | |
for ($j = 0; $j < $charCount; $j++) | |
{ | |
$tSplit = JString::str_ireplace($charMatches[0][$j], '', $terms[$i], false); | |
if (!empty($tSplit)) | |
{ | |
$terms[$i] = $tSplit; | |
} | |
else | |
{ | |
unset($terms[$i]); | |
} | |
$terms[] = $charMatches[0][$j]; | |
} | |
} | |
// Reset array keys. | |
$terms = array_values($terms); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment