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

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 中的 metaphone() 函数


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

登陆 | 还没注册?