PHP 字符串 levenshtein()函數(shù)
PHP字符串levenshtein()函數(shù)是內(nèi)置函數(shù)。愛(ài)掏網(wǎng) - it200.com它用于計(jì)算兩個(gè)字符串之間的距離。愛(ài)掏網(wǎng) - it200.com默認(rèn)情況下,PHP提供一些操作(替換,插入和刪除)
它返回兩個(gè)參數(shù)字符串之間的Levenshtein距離,如果字符串超過(guò)255個(gè)字符,則返回-1。愛(ài)掏網(wǎng) - it200.com
int levenshtein ( string str1 , stringstr2 , int cost_ins , intcost_rep , int $cost_del )
參數(shù) | 描述 | 必需/可選 |
---|---|---|
String1 | 指定第一個(gè)要比較的字符串。愛(ài)掏網(wǎng) - it200.com | 必需 |
String2 | 指定第二個(gè)要比較的字符串。愛(ài)掏網(wǎng) - it200.com | 必需 |
cost_ins | 指定插入操作的成本。愛(ài)掏網(wǎng) - it200.com | 可選 |
cost_rep | 指定替換操作的成本。愛(ài)掏網(wǎng) - it200.com | 可選 |
cost_del | 指定刪除操作的成本。愛(ài)掏網(wǎng) - it200.com | 可選 |
注意:levenshtein()函數(shù)對(duì)大小寫不敏感。愛(ài)掏網(wǎng) - it200.com
示例1
<?php
// In second string ?H? is not so it will return 1
echo levenshtein("Hello World","ello World");
?>
輸出:
1
示例2
<?php
// In second string ?He? is not so it will return 2
echo levenshtein("Hello World","llo World");
?>
輸出:
2
示例3
<?php
echo levenshtein("Hello PHP","ello PHP",10,20,30);
?>
輸出:
30
示例4
<?php
dist=levenshtein('javatpoint','VATPOINT');
echo "dist";
?>
輸出:
10
聲明:所有內(nèi)容來(lái)自互聯(lián)網(wǎng)搜索結(jié)果,不保證100%準(zhǔn)確性,僅供參考。如若本站內(nèi)容侵犯了原著者的合法權(quán)益,可聯(lián)系我們進(jìn)行處理。