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

PHP
PHP 介绍
PHP 安装
PHP 语法
PHP 变量
PHP操作符
PHP If...Else
PHP Switch
PHP 数组
PHP 循环
PHP 函数
PHP 表单
PHP $_GET
PHP $_POST
PHP Date
PHP Include
PHP 文件处理
PHP 文件上传
PHP Cookies
PHP Sessions
PHP 发送邮件

PHP 中的 similar_text() 函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 511 ::
收藏到网摘: 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

登陆 | 还没注册?