PHP soundex() 函數(shù)
定義和用法
soundex() 函數(shù)計算字符串的 soundex 鍵。
soundex 鍵是 4 字符長的字母數(shù)字字符串,表示一個單詞的英文發(fā)音。
soundex() 函數(shù)可用于拼寫檢查程序。
如果成功,則返回字符串的 soundex 鍵,如果失敗,則返回 false。
語法
soundex(string)
參數(shù) | 描述 |
---|---|
string | 必需。規(guī)定要檢查的字符串。 |
提示和注釋
注釋:soundex() 為發(fā)音相似的單詞創(chuàng)建相同的鍵。
提示:metaphone() 比 soundex() 函數(shù)更精確,因為 metaphone() 了解基本的英語發(fā)音規(guī)則。
例子
例子 1
<?php
$str = "hello";
echo soundex($str)
;
?>
輸出:
H400
例子 2
在本例中,我們對兩個發(fā)音相似的單詞應用 soundex() 函數(shù):
<?php $str = "Sun"; $str2 = "Son"; echosoundex($str)
; echo "<br />"; echosoundex($str2)
; ?>
輸出:
S500 S500