phpbar.de logo

Mailinglisten-Archive

[php] Alias-Suche - wie ...

[php] Alias-Suche - wie ...

Andreas Brandl php-mailinglist at andreas-brandl.de
Son Feb 13 22:33:00 CET 2005


Hallo Norbert,

Norbert Pfeiffer schrieb:
> 
> soundex() bringt es nicht wirklich:
> <?
> $WRT = array(
> 'Foto',
> 'Photo',
> 'Fotografie',
> 'Fotographie',
> 'Photografie',
> 'Photographie');
> foreach($WRT as $word) {
>     echo $word.' = '.soundex($word)."\n";
> }
> ?>
> erzeugt:
> Foto = F300
> Photo = P300
> Fotografie = F326
> Fotographie = F326
> Photografie = P326
> Photographie = P326
> 

Was gefällt dir daran nicht? Schaut doch gut aus...

Schau dir mal die UserComments unter [1] an. Vielleicht hilft dir das 
weiter.

Da heißts z.B. (ziemlich weit unten):
<snip>
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);
<snip>


[1] http://de.php.net/soundex

HTH,

Andi


php::bar PHP Wiki   -   Listenarchive