Skip to content

Instantly share code, notes, and snippets.

@luhaoming
Created October 18, 2017 03:17
Show Gist options
  • Save luhaoming/9672f182ab42edb6492ed5599c756f45 to your computer and use it in GitHub Desktop.
Save luhaoming/9672f182ab42edb6492ed5599c756f45 to your computer and use it in GitHub Desktop.
check the string contains big5 charactor
function withBig5($arg_strContent)
{
$blnEnglishOnly= true;
$intLoopCount = 0;
$intContentLength = strlen($arg_strContent);
while ($intLoopCount < $intContentLength)
{
$chrSingle = substr($arg_strContent,$intLoopCount,1);
if(ord($chrSingle) > 0x80)
{
$chrSingle = substr($arg_strContent,$intLoopCount,2);
$intLoopCount++;
if(isBig5($chrSingle))
{
$blnEnglishOnly = false;
break;
}
}
$intLoopCount++;
}
return !$blnEnglishOnly;
}
function isBig5($char="")
{
$bc = hexdec(bin2hex($char));
if(($bc>=0xa440 && $bc<= 0xc67e)||($bc>=0xc940 && $bc<= 0xf9dc))
{
return true;
}
else
{
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment