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

PHP
WINDOWS下安装MySQL
PHP 制作 网站/服务器 监视脚本
用PHP和CSS制作活动按钮
PHP 单件模式
PHP MVC模式,类封装以及HACK
PHP 中使用正则表达式
PHP 防止 SQL 注入攻击
PHP 跨站点脚本攻击
PHP 防止用户操纵 GET 变量
PHP 防止远程表单提交

PHP 中的 metaphone() 函数


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

Definition and Usage
定义和用法

The metaphone() function calculates the metaphone key of a string.
metaphone()函数的作用是:计算字符串的metaphone键。

A metaphone key represents how a string sounds if said by an English speaking person.
Metaphone键表示的是:指明一个字符的英文发音。

The metaphone() function can be used for spelling applications.
metaphone()函数可以应用于拼写。

This function returns the metaphone key of the string on success, or FALSE on failure.
如果这个函数执行成功,它将返回这个字符的metaphone键;如果执行失败将返回False。

Syntax
语法

metaphone(string,length)

Parameter参数 Description描述
string Required. Specifies the string to check
必要参数。指定字符串对象
length Optional. Specifies the maximum length of the metaphone key
可选参数。指定metaphone键的最大长度


Tips and Notes
提示和注意点

Note: The metaphone() function creates the same key for similar sounding words.
注意:metaphone()函数将为有着相似发音的单词创建相同的键。

Note: The generated metaphone keys vary in length.
注意:产生的metaphone键将依据长度发生变化。

Tip: metaphone() is more accurate than the soundex() function, because metaphone() knows the basic rules of English pronunciation.
提示:metaphone()函数比soundex()函数更加精确,因为metaphone()函数通晓英文发音的基本规则。


Example 1
案例1

<?php
echo metaphone("world");
?>

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

WRLT


Example 2
案例2

In this example we use the metaphone() function on two similar sounding words:
在下面的案例当中,我们将使用metaphone()函数对两个具有相同发音的单词进行操作:

<?php
$str = "Sun";
$str2 = "Son";
echo metaphone($str);
echo "<br />";
echo metaphone($str2);
?>

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

SN
SN

评论 (0) All

登陆 | 还没注册?