No cache version.

Caching disabled. Default setting for this page:enabled (code LNG204)
If the display is too slow, you can disable the user mode to view the cached version.

Vous devez être membre et vous identifier pour publier un article.
Les visiteurs peuvent toutefois commenter chaque article par une réponse.

SQL-PHP les soundex, ou booster votre recherche

Astuces de l’Infobrol (Développement)Article publié le 18/01/2006 08:13:42


Très pratique pour la recherche phonétique dans les tables de la DB.
Je conseille d'ailleurs de lire l'article dont est tirée cette astuce (voir le lien source).

  1. function soundex2( $sIn )
  2. {
  3. // Si il n'y a pas de mot, on sort immédiatement
  4. if ( $sIn === '' ) return ' ';
  5. // On met tout en minuscule
  6. $sIn = strtoupper( $sIn );
  7. // On supprime les accents
  8. $sIn = strtr( $sIn, 'ÂÄÀÇÈÉÊËŒÎÏÔÖÙÛÜ', 'AAASEEEEEIIOOUUU' );
  9. // On supprime tout ce qui n'est pas une lettre
  10. $sIn = preg_replace( '`[^A-Z]`', '', $sIn );
  11. // Si la chaîne ne fait qu'un seul caractère, on sort avec.
  12. if ( strlen( $sIn ) === 1 ) return $sIn . ' ';
  13. // on remplace les consonnances primaires
  14. $convIn = array( 'GUI', 'GUE', 'GA', 'GO', 'GU', 'CA', 'CO', 'CU', 'Q', 'CC', 'CK' );
  15. $convOut = array( 'KI', 'KE', 'KA', 'KO', 'K', 'KA', 'KO', 'KU', 'K','K', 'K' );
  16. $sIn = str_replace( $convIn, $convOut, $sIn );
  17. // on remplace les voyelles sauf le Y et sauf la première par A
  18. $sIn = preg_replace( '`(?‹!^)[EIOU]`', 'A', $sIn );
  19. // on remplace les préfixes puis on conserve la première lettre
  20. // et on fait les remplacements complémentaires
  21. $convIn = array( '`^KN`', '`^(PH|PF)`', '`^MAC`', '`^SCH`', '`^ASA`', '`(?‹!^)KN`', '`(?‹!^)(PH|PF)`', '`(?‹!^)MAC`',
  22. '`(?‹!^)SCH`','`(?‹!^)ASA`' );
  23. $convOut = array( 'NN', 'FF', 'MCC', 'SSS', 'AZA', 'NN', 'FF', 'MCC', 'SSS', 'AZA' );
  24. $sIn = preg_replace( $convIn, $convOut, $sIn );
  25. // suppression des H sauf CH ou SH
  26. $sIn = preg_replace( '`(?‹![CS])H`', '', $sIn );
  27. // suppression des Y sauf précédés d'un A
  28. $sIn = preg_replace( '`(?‹!A)Y`', '', $sIn );
  29. // on supprime les terminaisons A, T, D, S
  30. $sIn = preg_replace( '`[ATDS]$`', '', $sIn );
  31. // suppression de tous les A sauf en tête
  32. $sIn = preg_replace( '`(?!^)A`', '', $sIn );
  33. // on supprime les lettres répétitives
  34. $sIn = preg_replace( '`(.)\1`', '$1', $sIn );
  35. // on ne retient que 4 caractères ou on complète avec des blancs
  36. return substr( $sIn . ' ', 0, 4);
  37. }


Avatar :: adenine Un article de Adenine

Source : sqlpro.developpez.com


Sélection, tri et recherche d'articles
FILTRER :
TRIER :1er critère : 2e critère :
CHERCHER : Dans les titres Dans le contenu


[Afficher les liens en fonction des critères du formulaire ci-dessus]

English translation

You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.

If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.

Thank you in advance.

Document created the 13/09/2004, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/ast-rf-258.html

The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.