w3resource

PHP : metaphone() function

Description

The metaphone() function is used to calculate the metaphone key of a string.

Metaphone is a phonetic algorithm developed by Lawrence Philips. The algorithm produces variable length keys as its output, as opposed to Soundex's fixed-length keys. Similar sounding words share the same keys. It uses a larger set of rules for English pronunciation. Metaphone keys are very useful for text search and text matching applications.

Version:

(PHP 4 and above)

Syntax:

metaphone(input_string, key_length)

Parameter:

Name Description Required /
Optional
Type
input_string The input string. Required String
key_length Maximum length of the metaphone key. Optional Integer

Return value:

Returns the metaphone key as a string, FALSE in failure.

Value Type: String.

Pictorial Presentation

php-string-metaphone()

Example:

<?php
$str = "w3resource";
echo $str;
echo "<br />";
$str1 = "dual";
$str2 = "dwell";
echo metaphone($str1);
echo "<br />";
echo metaphone($str2);
?>

Output:

w3resource
TL
TWL

View the example in the browser

See also

PHP Function Reference

Previous: md5
Next: nl2br



PHP: Tips of the Day

Get the full URL in PHP

Have a look at $_SERVER['REQUEST_URI'], i.e.

Example:

$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

(Note that the double quoted string syntax is perfectly correct)

If you want to support both HTTP and HTTPS, you can use

$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

Editor's note: using this code has security implications. The client can set HTTP_HOST and REQUEST_URI to any arbitrary value it wants.

Ref : https://bit.ly/2ZYItNJ