note 106774 added to function.soundex
| From: | jluc at no-log dot org | Date: | Mon, 05 Dec 2011 19:45:18 +0000 |
| Subject: | note 106774 added to function.soundex | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-184918@lists.php.net to get a copy of this message | ||
The link for the code for french version is now 404. Here is a french oriented soundex. (original
function realised by Frédéric BROUARD - http://sqlpro.developpez.com/Soundex/).
<?php
function soundex2( $sIn ) {
// Si il n'y a pas de mot, on sort immédiatement
if ( $sIn === '' ) return ' ';
// On met tout en minuscule
$sIn = strtoupper( $sIn );
// On supprime les accents
$sIn = strtr( $sIn,
'ÃÃÃÃÃÃÃÃŒÃÃÃÃÃÃÃ',
'AAASEEEEEIIOOUUU' );
// On supprime tout ce qui n'est pas une lettre
$sIn = preg_replace( '
[^A-Z]', '', $sIn );
// Si la chaîne ne fait qu'un seul caractère, on sort avec.
if ( strlen( $sIn ) === 1 ) return $sIn . ' ';
// on remplace les consonnances primaires
$convIn = array( 'GUI', 'GUE', 'GA', 'GO',
'GU', 'CA', 'CO', 'CU',
'Q', 'CC', 'CK' );
$convOut = array( 'KI', 'KE', 'KA', 'KO', 'K',
'KA', 'KO', 'KU', 'K',
'K', 'K' );
$sIn = str_replace( $convIn, $convOut, $sIn );
// on remplace les voyelles sauf le Y et sauf la première par A
$sIn = preg_replace( '(?<!^)[EIOU]', 'A', $sIn );
// on remplace les préfixes puis on conserve la première lettre
// et on fait les remplacements complémentaires
$convIn = array( '^KN', '^(PH|PF)',
'^MAC', '^SCH', '^ASA',
'(?<!^)KN', '(?<!^)(PH|PF)',
'(?<!^)MAC', '(?<!^)SCH',
'(?<!^)ASA' );
$convOut = array( 'NN', 'FF', 'MCC', 'SSS',
'AZA', 'NN', 'FF', 'MCC',
'SSS', 'AZA' );
$sIn = preg_replace( $convIn, $convOut, $sIn );
// suppression des H sauf CH ou SH
$sIn = preg_replace( '(?<![CS])H', '', $sIn );
// suppression des Y sauf précédés d'un A
$sIn = preg_replace( '(?<!A)Y', '', $sIn );
// on supprime les terminaisons A, T, D, S
$sIn = preg_replace( '[ATDS]$', '', $sIn );
// suppression de tous les A sauf en tête
$sIn = preg_replace( '(?!^)A', '', $sIn );
// on supprime les lettres répétitives
$sIn = preg_replace( '(.)\1', '$1', $sIn );
// on ne retient que 4 caractères ou on complète avec des blancs
return substr( $sIn . ' ', 0, 4);
}
?>
----
Server IP: 89.31.146.176
Probable Submitter: 90.13.182.31
----
Manual Page -- http://www.php.net/manual/en/function.soundex.php
Edit -- https://master.php.net/note/edit/106774
Del: integrated -- https://master.php.net/note/delete/106774/integrated
Del: useless -- https://master.php.net/note/delete/106774/useless
Del: bad code -- https://master.php.net/note/delete/106774/bad+code
Del: spam -- https://master.php.net/note/delete/106774/spam
Del: non-english -- https://master.php.net/note/delete/106774/non-english
Del: in docs -- https://master.php.net/note/delete/106774/in+docs
Del: other reasons-- https://master.php.net/note/delete/106774
Reject -- https://master.php.net/note/reject/106774
Search -- https://master.php.net/manage/user-notes.php