The `metaphone()` function in PHP calculates the metaphone key of a string, which is a phonetic algorithm for indexing words by their English pronunciation. It's similar to `soundex()` but more accurate as it knows the basic rules of English pronunciation.PHP 8.PHP 8.1, PHP 8.2, PHP 8.3 and PHP 8.4.
Basic Syntax<?phpmetaphone(string $string, int $max_phonemes = 0): string?>`$string`: The input string`$max_phonemes`: Maximum length of the metaphone key (0 for unlimited)
Example Usage in PHP 8.2<?php$words = ['write', 'right', 'rite', 'wright','knight', 'night', 'their', 'there','weather', 'whether', 'phone', 'foam'];foreach ($words as $word) {$metaphone = metaphone($word);echo "$word: $metaphone\n";}
Notes1. Metaphone is more accurate than Soundex for English words2. It works best with single words rather than phrases3. The algorithm is designed for English pronunciation4. In PHP 8.2, the function behaves the same as in previous versionsMetaphone is particularly useful for search systems where you want to find matches even when words are misspelled but sound similar.VV