Friday, October 10, 2025
HomeLanguagesPHP soundex() Function

PHP soundex() Function

The soundex() function is a built-in function in PHP and is used to calculate the Soundex key of a given string. The soundex key is a four character long alphanumeric string(starting with a letter) which represents the English pronunciation of the given string. 

Syntax:

string soundex($str);

Parameters: This function accepts a single parameter $str which represents the string for which we want to find the Soundex key. 

Return Value: It returns the soundex key as a string. 

Below programs illustrate the soundex() function in PHP: 

Program 1: In the below program, the soundex() function generates the soundex key of the string “neveropen”. 

php




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


Output:

G216

Program 2: In the below program, we will see that two words having same pronunciation produce similar Soundex key. 

php




<?php
  
$str1 = "hair";
$str2 = "heir";
  
echo soundex($str1)."\n";
echo soundex($str2);
  
?>


Output:

H600
H600

Reference: http://php.net/manual/en/function.soundex.php

RELATED ARTICLES

Most Popular

Dominic
32349 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6715 POSTS0 COMMENTS
Nicole Veronica
11878 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6837 POSTS0 COMMENTS
Ted Musemwa
7097 POSTS0 COMMENTS
Thapelo Manthata
6792 POSTS0 COMMENTS
Umr Jansen
6791 POSTS0 COMMENTS