PHPのsimilar_text()関数
例
2つの文字列間の類似性を計算し、一致する文字を返します。
<?php
echo similar_text("Hello World","Hello Peter");
?>
定義と使用法
like_text()関数は、2つの文字列間の類似性を計算します。
また、2つの文字列の類似度をパーセントで計算することもできます。
注:levenshtein()関数は、similar_text()関数よりも高速です。ただし、similar_text()関数を使用すると、必要な変更を少なくして、より正確な結果を得ることができます。
構文
similar_text(string1,string2,percent)
パラメータ値
Parameter | Description |
---|---|
string1 | Required. Specifies the first string to be compared |
string2 | Required. Specifies the second string to be compared |
percent | Optional. Specifies a variable name for storing the similarity in percent |
技術的な詳細
戻り値: | 2つの文字列の一致する文字数を返します |
---|---|
PHPバージョン: | 4歳以上 |
その他の例
例
2つの文字列間の類似度をパーセントで計算します。
<?php
similar_text("Hello World","Hello Peter",$percent);
echo $percent;
?>
❮PHP文字列リファレンス