note 22210 added to function.soundex

From: Date: Mon, 10 Jun 2002 20:25:25 +0000
Subject: note 22210 added to function.soundex
Groups: php.notes 
Request: Send a blank email to php-notes+get-31675@lists.php.net to get a copy of this message
Although the standard soundex string is 4 characters long, and this is what's returned by the php function, some database programs return an arbitrary number of strings. MySQL, for instance. The MySQL documentation covers this, recommending that you may wish to use substring to output the standard 4 characters. Let's take 'Dostoyevski' as an example. select soundex("Dostoyevski") returns D2312 select substring(soundex("Dostoyevski"), 1, 4); returns D231 PHP will return the value as 'D231' So, to use the soundex function to generate a WHERE parameter in a MySQL SELECT statement, you might try this: $s = soundex('Dostoyevski'); SELECT * FROM authors WHERE substring(soundex(lastname), 1 , 4) = "' . $s . '"'; Or, if you want to bypass the php function $result = mysql_query("select soundex('Dostoyevski')"); $s = mysql_result($result, 0, 0); -- http://www.php.net/manual/en/function.soundex.php http://master.php.net/manage/user-notes.php?action=edit+22210 http://master.php.net/manage/user-notes.php?action=delete+22210 http://master.php.net/manage/user-notes.php?action=reject+22210

« previous php.notes (#31675) next »