View difference between Paste ID: f1819c394 and
SHOW: | | - or go back to the newest paste.
1-
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
E-mail: Fred.lucena@unibratec.com.br 
12
*/
13
//echo SoundexBR("valter");
14
15
class BuscaBR
16
{
17
	static public function Fonetica($nome,$delimitador = FALSE)
18
	{
19
		if (strpos($nome," ") !== FALSE)
20
		{
21
			$nome1 = explode(" ",$nome);
22
			foreach($nome1 as &$val)
23
				$val = self::SoundexBR($val);
24
			
25
			$nome1 = implode(" ",$nome1);
26
		}
27
		else
28
			$nome1 = self::SoundexBR($nome);
29
			
30
		$nome1 = trim($nome1);
31
		if ($delimitador)
32
			$nome1 = "/ $nome1 /";
33
		else
34
			$nome1 = " $nome1 ";
35
		return $nome1;
36
	}
37
	
38
	public function SoundexBR ($string)
39
	{
40
		$string=trim($string);
41
		//1. Para Minuscula - Faster Insensitive
42
		$string = utf8_decode($string);
43
		$string = strtolower($string);
44
		$string = utf8_encode($string);
45
		//2. Remove Acentos
46
		$arr = array(
47
		"�"=>"a",
48
		"�"=>"a",
49
		"�"=>"a",
50
		"�"=>"a",
51
		"�"=>"a",
52
		"�"=>"e",
53
		"�"=>"e",
54
		"�"=>"e",
55
		"�"=>"e",
56
		"�"=>"i",
57
		"�"=>"i",
58
		"�"=>"i",
59
		"�"=>"i",
60
		"�"=>"o",
61
		"�"=>"o",
62
		"�"=>"o",
63
		"�"=>"o",
64
		"�"=>"o",
65
		"�"=>"u",
66
		"�"=>"u",
67
		"�"=>"u",
68
		"�"=>"u"
69
		);
70
		$string = strtr($string,$arr);
71
		$arr = array(
72
		"bl"=>"b", //4
73
		"br"=>"b", //4
74
		"ca"=>"k", //8
75
		"ce"=>"s",
76
		"ci"=>"s",
77
		"co"=>"k", //8
78
		"cu"=>"k", //8
79
		"ck"=>"k", //8
80
		"�"=>"s", //13
81
		"ch"=>"s", //13
82
		"ct"=>"t",
83
		"ge"=>"j",
84
		"gi"=>"j",
85
		"gm"=>"m",
86
		"gl"=>"g",
87
		"gr"=>"g",
88
		"l"=>"r",
89
		"n"=>"m",
90
		"md"=>"m",
91
		"mg"=>"g",
92
		"mj"=>"j",
93
		"ph"=>"f",
94
		"pr"=>"p",
95
		"q"=>"k",
96
		"rg"=>"g",
97
		"rs"=>"s",
98
		"rt"=>"t",
99
		"rm"=>"sm",
100
		"rj"=>"j",
101
		"st"=>"t",
102
		"tr"=>"t",
103
		"tl"=>"t",
104
		"ts"=>"s",
105
		"w"=>"v",
106
		"x"=>"s",
107
		"st"=>"t",
108
		"y"=>"i",
109
		"z"=>"s",
110
		);
111
		$string = strtr($string,$arr);
112
		if (substr($string,-2) == "ao")	$string = substr($string,0,-2)."m"; //10
113
		//Termincao S z R M N AO L
114
		if (substr($string,-1) == "s")	$string = substr($string,0,-1); //16
115
		if (substr($string,-1) == "z")	$string = substr($string,0,-1); //16
116
		if (substr($string,-1) == "r")	$string = substr($string,0,-1); //16
117
		if (substr($string,-1) == "r")	$string = substr($string,0,-1); //16
118
		if (substr($string,-1) == "m")	$string = substr($string,0,-1); //16
119
		if (substr($string,-1) == "n")	$string = substr($string,0,-1); //16
120
		if (substr($string,-2) == "ao")	$string = substr($string,0,-2); //16
121
		if (substr($string,-1) == "l")	$string = substr($string,0,-1); //16
122
		$arr = array(
123
		"r"=>"l", //17
124
		"h"=>"", //18
125
		"a"=>"", //18
126
		"e"=>"", //18
127
		"i"=>"", //18
128
		"o"=>"", //18
129
		"u"=>"", //18
130
		"aa"=>"a",//19
131
		"bb"=>"b",
132
		"cc"=>"c",
133
		"dd"=>"d",
134
		"ee"=>"e",
135
		"ff"=>"f",
136
		"gg"=>"g",
137
		"hh"=>"h",
138
		"ii"=>"i",
139
		"jj"=>"j",
140
		"kk"=>"k",
141
		"ll"=>"l",
142
		"mm"=>"m",
143
		"nn"=>"n",
144
		"oo"=>"o",
145
		"pp"=>"p",
146
		"qq"=>"q",
147
		"rr"=>"r",
148
		"ss"=>"s",
149
		"tt"=>"t",
150
		"uu"=>"y",
151
		"vv"=>"v",
152
		"ww"=>"w",
153
		"xx"=>"x",
154
		"yy"=>"y",
155
		"zz"=>"z" //19
156
		);
157
		$string = strtr($string,$arr);
158
		return $string;
159
	}
160
}
161
162
?>