PHP calculates the key function metaphone() of a string

黄舟
Release: 2023-03-16 22:26:02
Original
1457 people have browsed it

Example

Calculate the metaphone key of "World":

<?php
echo metaphone("World");
?>
Copy after login

Definition and usage

metaphone() function calculates the metaphone key of a string.

The metaphone key represents the English pronunciation of the string.

Themetaphone() function can be used in spell checkers.

Note: The metaphone() function creates the same key for words with similar pronunciation.

Note: The generated metaphone keys are of variable length.

Tip: metaphone() is more precise than the soundex() function because metaphone() understands the basic rules of English pronunciation.

Syntax

metaphone(string,length)
Copy after login

Parameter Description

string Required. Specifies the string to check.

length Optional. Specifies the maximum length of metaphone keys. ​

Technical details

Return value:       Returns the metaphone key of the string if successful, returns FALSE if failed.

PHP version: 4+

More examples

Example 1

Use metaphone() function for two words with similar pronunciation:

<?php
$str = "Assistance";
$str2 = "Assistants";

echo metaphone($str);
echo "<br>";
echo metaphone($str2);
?>
Copy after login

Example 2

Use length parameter:

<?php
$str = "Assistance";
$str2 = "Assistants";

echo metaphone($str,5);
echo "<br>";
echo metaphone($str2,5);
?>
Copy after login


The above is the detailed content of PHP calculates the key function metaphone() of a string. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!