Skip to content

Instantly share code, notes, and snippets.

@elinw
Created January 13, 2012 22:28
Show Gist options
  • Save elinw/1609111 to your computer and use it in GitHub Desktop.
Save elinw/1609111 to your computer and use it in GitHub Desktop.
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