Japanese Field Pattern
To extract hiragana, katakana, kanji portion of a Japanese text, explicity set the unicode range AND specify u modifier for the pattern.
<?php echo "Hiragana -- "; $pattern ='/[^\x{3040}-\x{309F}]+/u'; $s=preg_replace($pattern,"",$str); echo $s."<br />"; echo "Katakana -- "; $pattern ='/[^\x{30A0}-\x{30FF}]+/u'; $s=preg_replace($pattern,"",$str); echo $s."<br />"; echo "Kanji -- "; $pattern ='/[^\x{4E00}-\x{9FBF}]+/u'; $s=preg_replace($pattern,"",$str); echo $s."<br />"; ?> |
Posted in PHP