最近我们在做高考小语种的项目,需要检测到字符串中是否是日语,这里记录一下代码段
<?php
$word = "激安価格お買い得タイヨー脱腸帯·片側用 fm 腰回り";
$word2 = "This is the english language";
function isJapanese($lang) {
return preg_match('/[\x{4E00}-\x{9FBF}\x{3040}-\x{309F}\x{30A0}-\x{30FF}]/u', $lang);
}
var_dump(isJapanese($word)); //returns 1
var_dump(isJapanese($word2));//returns 0