I want to have different process for English word and Japanese word in this function
function process_word($word) {
if($word is english) {
/////////
}else if($word is japanese) {
////////
}
}
thank you
A quick solution that doesn't need the mb_string
extension:
if (strlen($str) != strlen(utf8_decode($str))) {
// $str uses multi-byte chars (isn't English)
}
else {
// $str is ASCII (probably English)
}
Or a modification of the solution provided by @Alexander Konstantinov:
function isKanji($str) {
return preg_match('/[\x{4E00}-\x{9FBF}]/u', $str) > 0;
}
function isHiragana($str) {
return preg_match('/[\x{3040}-\x{309F}]/u', $str) > 0;
}
function isKatakana($str) {
return preg_match('/[\x{30A0}-\x{30FF}]/u', $str) > 0;
}
function isJapanese($str) {
return isKanji($str) || isHiragana($str) || isKatakana($str);
}
This function checks whether a word contains at least one Japanese letter (I found unicode range for Japanese letters in Wikipedia).
function isJapanese($word) {
return preg_match('/[\x{4E00}-\x{9FBF}\x{3040}-\x{309F}\x{30A0}-\x{30FF}]/u', $word);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With