Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- echo BuscaBR::Fonetica("Jos da Silva", 1); //O 1 aqui faz com que o retorno venha delimitado por //...
- echo BuscaBR::Fonetica("Jos da Silva");
- /* BUSCABR*/
- /*
- http://www.unibratec.com.br/jornadacientifica/diretorio/NOVOB.pdf
- Baseado no Algoritimo de FRED JORGE TAVARES DE LUCENA
- E-mail: Fred.lucena@unibratec.com.br
- */
- //echo SoundexBR("valter");
- class BuscaBR
- {
- static public function Fonetica($nome,$delimitador = FALSE)
- {
- if (strpos($nome," ") !== FALSE)
- {
- $nome1 = explode(" ",$nome);
- foreach($nome1 as &$val)
- $val = self::SoundexBR($val);
- $nome1 = implode(" ",$nome1);
- }
- else
- $nome1 = self::SoundexBR($nome);
- $nome1 = trim($nome1);
- if ($delimitador)
- $nome1 = "/ $nome1 /";
- else
- $nome1 = " $nome1 ";
- return $nome1;
- }
- public function SoundexBR ($string)
- {
- $string=trim($string);
- //1. Para Minuscula - Faster Insensitive
- $string = utf8_decode($string);
- $string = strtolower($string);
- $string = utf8_encode($string);
- //2. Remove Acentos
- $arr = array(
- ""=>"a",
- ""=>"a",
- ""=>"a",
- ""=>"a",
- ""=>"a",
- ""=>"e",
- ""=>"e",
- ""=>"e",
- ""=>"e",
- ""=>"i",
- ""=>"i",
- ""=>"i",
- ""=>"i",
- ""=>"o",
- ""=>"o",
- ""=>"o",
- ""=>"o",
- ""=>"o",
- ""=>"u",
- ""=>"u",
- ""=>"u",
- ""=>"u"
- );
- $string = strtr($string,$arr);
- $arr = array(
- "bl"=>"b", //4
- "br"=>"b", //4
- "ca"=>"k", //8
- "ce"=>"s",
- "ci"=>"s",
- "co"=>"k", //8
- "cu"=>"k", //8
- "ck"=>"k", //8
- ""=>"s", //13
- "ch"=>"s", //13
- "ct"=>"t",
- "ge"=>"j",
- "gi"=>"j",
- "gm"=>"m",
- "gl"=>"g",
- "gr"=>"g",
- "l"=>"r",
- "n"=>"m",
- "md"=>"m",
- "mg"=>"g",
- "mj"=>"j",
- "ph"=>"f",
- "pr"=>"p",
- "q"=>"k",
- "rg"=>"g",
- "rs"=>"s",
- "rt"=>"t",
- "rm"=>"sm",
- "rj"=>"j",
- "st"=>"t",
- "tr"=>"t",
- "tl"=>"t",
- "ts"=>"s",
- "w"=>"v",
- "x"=>"s",
- "st"=>"t",
- "y"=>"i",
- "z"=>"s",
- );
- $string = strtr($string,$arr);
- if (substr($string,-2) == "ao") $string = substr($string,0,-2)."m"; //10
- //Termincao S z R M N AO L
- if (substr($string,-1) == "s") $string = substr($string,0,-1); //16
- if (substr($string,-1) == "z") $string = substr($string,0,-1); //16
- if (substr($string,-1) == "r") $string = substr($string,0,-1); //16
- if (substr($string,-1) == "r") $string = substr($string,0,-1); //16
- if (substr($string,-1) == "m") $string = substr($string,0,-1); //16
- if (substr($string,-1) == "n") $string = substr($string,0,-1); //16
- if (substr($string,-2) == "ao") $string = substr($string,0,-2); //16
- if (substr($string,-1) == "l") $string = substr($string,0,-1); //16
- $arr = array(
- "r"=>"l", //17
- "h"=>"", //18
- "a"=>"", //18
- "e"=>"", //18
- "i"=>"", //18
- "o"=>"", //18
- "u"=>"", //18
- "aa"=>"a",//19
- "bb"=>"b",
- "cc"=>"c",
- "dd"=>"d",
- "ee"=>"e",
- "ff"=>"f",
- "gg"=>"g",
- "hh"=>"h",
- "ii"=>"i",
- "jj"=>"j",
- "kk"=>"k",
- "ll"=>"l",
- "mm"=>"m",
- "nn"=>"n",
- "oo"=>"o",
- "pp"=>"p",
- "qq"=>"q",
- "rr"=>"r",
- "ss"=>"s",
- "tt"=>"t",
- "uu"=>"y",
- "vv"=>"v",
- "ww"=>"w",
- "xx"=>"x",
- "yy"=>"y",
- "zz"=>"z" //19
- );
- $string = strtr($string,$arr);
- return $string;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement