Advertisement
Guest User

OTAV

a guest
Jan 16th, 2010
1,253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.20 KB | None | 0 0
  1. <?php
  2.  
  3. echo BuscaBR::Fonetica("Jos� da Silva", 1); //O 1 aqui faz com que o retorno venha delimitado por //...
  4. echo BuscaBR::Fonetica("Jos� da Silva");
  5.  
  6. /* BUSCABR*/
  7.  
  8. /*
  9. http://www.unibratec.com.br/jornadacientifica/diretorio/NOVOB.pdf
  10. Baseado no Algoritimo de FRED JORGE TAVARES DE LUCENA
  11. */
  12. //echo SoundexBR("valter");
  13.  
  14. class BuscaBR
  15. {
  16.     static public function Fonetica($nome,$delimitador = FALSE)
  17.     {
  18.         if (strpos($nome," ") !== FALSE)
  19.         {
  20.             $nome1 = explode(" ",$nome);
  21.             foreach($nome1 as &$val)
  22.                 $val = self::SoundexBR($val);
  23.            
  24.             $nome1 = implode(" ",$nome1);
  25.         }
  26.         else
  27.             $nome1 = self::SoundexBR($nome);
  28.            
  29.         $nome1 = trim($nome1);
  30.         if ($delimitador)
  31.             $nome1 = "/ $nome1 /";
  32.         else
  33.             $nome1 = " $nome1 ";
  34.         return $nome1;
  35.     }
  36.    
  37.     public function SoundexBR ($string)
  38.     {
  39.         $string=trim($string);
  40.         //1. Para Minuscula - Faster Insensitive
  41.         $string = utf8_decode($string);
  42.         $string = strtolower($string);
  43.         $string = utf8_encode($string);
  44.         //2. Remove Acentos
  45.         $arr = array(
  46.         "�"=>"a",
  47.         "�"=>"a",
  48.         "�"=>"a",
  49.         "�"=>"a",
  50.         "�"=>"a",
  51.         "�"=>"e",
  52.         "�"=>"e",
  53.         "�"=>"e",
  54.         "�"=>"e",
  55.         "�"=>"i",
  56.         "�"=>"i",
  57.         "�"=>"i",
  58.         "�"=>"i",
  59.         "�"=>"o",
  60.         "�"=>"o",
  61.         "�"=>"o",
  62.         "�"=>"o",
  63.         "�"=>"o",
  64.         "�"=>"u",
  65.         "�"=>"u",
  66.         "�"=>"u",
  67.         "�"=>"u"
  68.         );
  69.         $string = strtr($string,$arr);
  70.         $arr = array(
  71.         "bl"=>"b", //4
  72.         "br"=>"b", //4
  73.         "ca"=>"k", //8
  74.         "ce"=>"s",
  75.         "ci"=>"s",
  76.         "co"=>"k", //8
  77.         "cu"=>"k", //8
  78.         "ck"=>"k", //8
  79.         "�"=>"s", //13
  80.         "ch"=>"s", //13
  81.         "ct"=>"t",
  82.         "ge"=>"j",
  83.         "gi"=>"j",
  84.         "gm"=>"m",
  85.         "gl"=>"g",
  86.         "gr"=>"g",
  87.         "l"=>"r",
  88.         "n"=>"m",
  89.         "md"=>"m",
  90.         "mg"=>"g",
  91.         "mj"=>"j",
  92.         "ph"=>"f",
  93.         "pr"=>"p",
  94.         "q"=>"k",
  95.         "rg"=>"g",
  96.         "rs"=>"s",
  97.         "rt"=>"t",
  98.         "rm"=>"sm",
  99.         "rj"=>"j",
  100.         "st"=>"t",
  101.         "tr"=>"t",
  102.         "tl"=>"t",
  103.         "ts"=>"s",
  104.         "w"=>"v",
  105.         "x"=>"s",
  106.         "st"=>"t",
  107.         "y"=>"i",
  108.         "z"=>"s",
  109.         );
  110.         $string = strtr($string,$arr);
  111.         if (substr($string,-2) == "ao") $string = substr($string,0,-2)."m"; //10
  112.         //Termincao S z R M N AO L
  113.         if (substr($string,-1) == "s")  $string = substr($string,0,-1); //16
  114.         if (substr($string,-1) == "z")  $string = substr($string,0,-1); //16
  115.         if (substr($string,-1) == "r")  $string = substr($string,0,-1); //16
  116.         if (substr($string,-1) == "r")  $string = substr($string,0,-1); //16
  117.         if (substr($string,-1) == "m")  $string = substr($string,0,-1); //16
  118.         if (substr($string,-1) == "n")  $string = substr($string,0,-1); //16
  119.         if (substr($string,-2) == "ao") $string = substr($string,0,-2); //16
  120.         if (substr($string,-1) == "l")  $string = substr($string,0,-1); //16
  121.         $arr = array(
  122.         "r"=>"l", //17
  123.         "h"=>"", //18
  124.         "a"=>"", //18
  125.         "e"=>"", //18
  126.         "i"=>"", //18
  127.         "o"=>"", //18
  128.         "u"=>"", //18
  129.         "aa"=>"a",//19
  130.         "bb"=>"b",
  131.         "cc"=>"c",
  132.         "dd"=>"d",
  133.         "ee"=>"e",
  134.         "ff"=>"f",
  135.         "gg"=>"g",
  136.         "hh"=>"h",
  137.         "ii"=>"i",
  138.         "jj"=>"j",
  139.         "kk"=>"k",
  140.         "ll"=>"l",
  141.         "mm"=>"m",
  142.         "nn"=>"n",
  143.         "oo"=>"o",
  144.         "pp"=>"p",
  145.         "qq"=>"q",
  146.         "rr"=>"r",
  147.         "ss"=>"s",
  148.         "tt"=>"t",
  149.         "uu"=>"y",
  150.         "vv"=>"v",
  151.         "ww"=>"w",
  152.         "xx"=>"x",
  153.         "yy"=>"y",
  154.         "zz"=>"z" //19
  155.         );
  156.         $string = strtr($string,$arr);
  157.         return $string;
  158.     }
  159. }
  160.  
  161. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement