JpnForPhp\Analyzer\Analyzer::countKanji PHP Method

countKanji() public static method

Count number of kanji within the specified string.
public static countKanji ( string $str, boolean $extended = false ) : integer
$str string The input string.
$extended boolean Determines whether to use the extended kanji set
return integer Returns the number of kanji.
    public static function countKanji($str, $extended = false)
    {
        $matches = array();
        if ($extended) {
            return preg_match_all(Helper::PREG_PATTERN_KANJI_EXTENDED, $str, $matches);
        } else {
            return preg_match_all(Helper::PREG_PATTERN_KANJI, $str, $matches);
        }
    }

Usage Example

Example #1
0
 public function testCountKanjiExtended()
 {
     $result = Analyzer::countKanji('三ヶ日', TRUE);
     $this->assertEquals(3, $result);
 }
All Usage Examples Of JpnForPhp\Analyzer\Analyzer::countKanji