Home >Backend Development >PHP Tutorial >PHP calculates the soundex key function soundex() of a string

PHP calculates the soundex key function soundex() of a string

黄舟
黄舟Original
2017-11-03 09:14:111351browse

Example

Calculate the soundex key of "Hello":

<?php
$str = "Hello";
echo soundex($str);
?>

Definition and usage

soundex() function calculates the soundex key of string .

The soundex key is a 4-character long alphanumeric string that represents the English pronunciation of a word.

The soundex() function can be used in spell checkers.

Note: The soundex() function creates the same key for words that sound similar.

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

Syntax

soundex(string)
Parameters Description
string Required. Specifies the string to check.

Technical details

Return value: Returns the soundex key of the string if successful , and returns FALSE if it fails.
PHP version: 4+
##More examples

Example 1

Use the soundex() function for two words with similar pronunciation:

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

echo soundex($str);
echo "<br>";
echo soundex($str2);
?>

Split the string "Shanghai" into an array:

<?php
print_r(str_split("Shanghai"));
?>


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

Statement:
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