当前位置: 首页 > 网络学院 > 服务端脚本教程 > PHP > similar_text() 函数

PHP
PHP Libxml
PHP Math
PHP Misc
PHP MySQL
PHP SimpleXML
PHP String
PHP XML
PHP Zip
PHP Mail
用PHP5的DirectoryIterators递归扫描目录
PHP 阻止SQL注入式攻击
PHP5面向对象 - 基础 - 类和对象
PHP5面向对象 - 基础 - 类的属性( public )
PHP5面向对象 - 基础 - 类的属性( private )
PHP5面向对象 - 基础 - 方法
PHP5面向对象 - 基础 - 对象的比较
php5面向对象 - 基础 - 构造函数
php5面向对象 - 基础 - 析构函数
用PHP控制用户的浏览器 - ob*函数的使用
PHP PDO 学习笔记

PHP 中的 similar_text() 函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 514 ::
收藏到网摘: n/a

Definition and Usage
定义和用法

The similar_text() function returns the number of matching characters of two strings.
similar_text()函数的作用是:返回两个字符串中相匹配的字符数量。

It can also calculate the similarity of the two strings in percent.
它同样可以计算两个字符串的相似性(用“百分比%”来表示)。

Syntax
语法

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
可选参数。指定一个用来存储相似性的变量名(用“百分比%”来表示)


Tips and Notes
注意点

Note: The levenshtein() function is faster than the similar_text() function. However, the similar_text() function will give you a more accurate result with less modifications needed.
注意:levenshtein()函数的运行速度要快于similar_text()函数。然而,similar_text()函数将会给出相对于levenshtein()函数而言更精确的结果,并且你无需对其进行过多修改。


Example 1
案例1

<?php
echo similar_text("Hello World","Hello Peter");
?>

The output of the code above will be:
上述代码将输出下面的结果:

7


Example 2
案例2

<?php
similar_text("Hello World","Hello Peter",$percent);
echo $percent;
?>

The output of the code above will be:
上述代码将输出下面的结果:

63.6363636364

评论 (0) All

登陆 | 还没注册?