128 of 410 menu

Soundex Function

soundex function calculates a sound key for a given string. The soundex key consists of the first letter of the string, followed by three digits that represent the main sound characteristics of the rest of the string. This algorithm is especially useful for finding names that sound similar but may be spelled differently.

Syntax

soundex(string);

Example

Get the soundex key for the string "Hello":

<?php echo soundex('Hello'); ?>

Code execution result:

'H400'

Example

Compare soundex keys for words that sound similar:

<?php $res1 = soundex('Robert'); $res2 = soundex('Rupert'); echo $res1 . ' ' . $res2; ?>

Code execution result:

'R163 R163'

Example

Check soundex keys for different words:

<?php $words = ['Hello', 'Hallo', 'Hullo', 'World']; foreach ($words as $word) { echo $word . ': ' . soundex($word) . "\n"; } ?>

Code execution result:

Hello: H400 Hallo: H400 Hullo: H400 World: W643

See Also

  • levenshtein function,
    which calculates the distance between strings
  • metaphone function,
    which returns the metaphone key for a string
မြန်မာ
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEnglishEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
ဝက်ဘ်ဆိုက် လုပ်ဆောင်ခြင်း၊ ဆန်းစစ်လေ့လာခြင်းနှင့် ပုဂ္ဂလိကပြုပြင်ခြင်းအတွက် ကျွန်ုပ်တို့သည် cookie များကို အသုံးပြုပါသည်။ ဒေတာများကို ပြုပြင်ခြင်းသည် ကိုယ်ရေးကိုယ်တာ မူဝါဒအတိုင်း ဖြစ်ပါသည်။
အားလုံးလက်ခံရန် ပြင်ဆင်ရန် ငြင်းပယ်ရန်