Commit 1d82d2d9e22af63e39c5eb07e9ace2a29962c798
1 parent
fdab6249
Exists in
master
and in
7 other branches
Criação de uma função única para realizar a conversão de caracteres de ISO para UTF
Showing
1 changed file
with
33 additions
and
18 deletions
Show diff stats
classesphp/classe_atributos.php
| @@ -254,8 +254,7 @@ $tipo - Tipo de busca brasil|null | @@ -254,8 +254,7 @@ $tipo - Tipo de busca brasil|null | ||
| 254 | $shp_index = $result->shapeindex; | 254 | $shp_index = $result->shapeindex; |
| 255 | $shape = $this->layer->getfeature($shp_index,-1); | 255 | $shape = $this->layer->getfeature($shp_index,-1); |
| 256 | $v = trim($shape->values[$item]); | 256 | $v = trim($shape->values[$item]); |
| 257 | - if (function_exists("mb_convert_encoding")) | ||
| 258 | - {$v = mb_convert_encoding($v,"UTF-8","ISO-8859-1");} | 257 | + $v = $this->converte($v); |
| 259 | $valitem[] = $v; | 258 | $valitem[] = $v; |
| 260 | } | 259 | } |
| 261 | $registros[] = implode(";",$valitem); | 260 | $registros[] = implode(";",$valitem); |
| @@ -328,8 +327,7 @@ $tipolista - Indica se serão mostrados todos os registros ou apenas os seleciona | @@ -328,8 +327,7 @@ $tipolista - Indica se serão mostrados todos os registros ou apenas os seleciona | ||
| 328 | $shp_index = $result->shapeindex; | 327 | $shp_index = $result->shapeindex; |
| 329 | $shape = $this->layer->getfeature($shp_index,-1); | 328 | $shape = $this->layer->getfeature($shp_index,-1); |
| 330 | $valori = trim($shape->values[$item]); | 329 | $valori = trim($shape->values[$item]); |
| 331 | - if (function_exists("mb_convert_encoding")) | ||
| 332 | - {$valori = mb_convert_encoding($valori,"UTF-8","ISO-8859-1");} | 330 | + $valori = $this->converte($valori); |
| 333 | $valitem[] = array("item"=>$item,"valor"=>$valori); | 331 | $valitem[] = array("item"=>$item,"valor"=>$valori); |
| 334 | } | 332 | } |
| 335 | $registros[] = array("indice"=>$shp_index,"valores"=>$valitem,"status"=>$chk); | 333 | $registros[] = array("indice"=>$shp_index,"valores"=>$valitem,"status"=>$chk); |
| @@ -370,7 +368,7 @@ $tipolista - Indica se serão mostrados todos os registros ou apenas os seleciona | @@ -370,7 +368,7 @@ $tipolista - Indica se serão mostrados todos os registros ou apenas os seleciona | ||
| 370 | { | 368 | { |
| 371 | $valori = ($shape->values[$item]); | 369 | $valori = ($shape->values[$item]); |
| 372 | } | 370 | } |
| 373 | - $valori = $valori = mb_convert_encoding($valori,"UTF-8","ISO-8859-1"); | 371 | + $valori = $this->converte($valori); |
| 374 | $valitem[] = array("item"=>$item,"valor"=>$valori); | 372 | $valitem[] = array("item"=>$item,"valor"=>$valori); |
| 375 | } | 373 | } |
| 376 | //if (in_array($shp_index,$shp_atual)) | 374 | //if (in_array($shp_index,$shp_atual)) |
| @@ -436,7 +434,7 @@ $onde - Tipo de abrangência espacial (brasil ou mapa) | @@ -436,7 +434,7 @@ $onde - Tipo de abrangência espacial (brasil ou mapa) | ||
| 436 | $filtro = $l->getfilterstring(); | 434 | $filtro = $l->getfilterstring(); |
| 437 | if ($filtro != ""){$l->setfilter("");} | 435 | if ($filtro != ""){$l->setfilter("");} |
| 438 | $buscas = "ÁÃÓÕÔáàãâóòôõúûíéêç"; | 436 | $buscas = "ÁÃÓÕÔáàãâóòôõúûíéêç"; |
| 439 | - $buscasUTF = mb_convert_encoding($buscas,"UTF-8","ISO-8859-1"); | 437 | + $buscaUTF = $this->converte($buscas); |
| 440 | $trocas = "AAOOOaaaaoooouuieecAAOOOaaaaoooouuieec"; | 438 | $trocas = "AAOOOaaaaoooouuieecAAOOOaaaaoooouuieec"; |
| 441 | $buscas = $buscas.$buscasUTF; | 439 | $buscas = $buscas.$buscasUTF; |
| 442 | $sopen = $l->open(); | 440 | $sopen = $l->open(); |
| @@ -454,8 +452,7 @@ $onde - Tipo de abrangência espacial (brasil ou mapa) | @@ -454,8 +452,7 @@ $onde - Tipo de abrangência espacial (brasil ou mapa) | ||
| 454 | { | 452 | { |
| 455 | if (strtr($v,$buscas,$trocas) == strtr($palavra,$buscas,$trocas)) | 453 | if (strtr($v,$buscas,$trocas) == strtr($palavra,$buscas,$trocas)) |
| 456 | { | 454 | { |
| 457 | - if (function_exists("mb_convert_encoding")) | ||
| 458 | - {$v = mb_convert_encoding($v,"UTF-8","ISO-8859-1");} | 455 | + $v = $this->converte($v); |
| 459 | $r[] = array("item" => $item,"valor" => $v); | 456 | $r[] = array("item" => $item,"valor" => $v); |
| 460 | $encontrado = "sim"; | 457 | $encontrado = "sim"; |
| 461 | } | 458 | } |
| @@ -464,8 +461,7 @@ $onde - Tipo de abrangência espacial (brasil ou mapa) | @@ -464,8 +461,7 @@ $onde - Tipo de abrangência espacial (brasil ou mapa) | ||
| 464 | { | 461 | { |
| 465 | if (stristr(strtr($v,$buscas,$trocas),strtr($palavra,$buscas,$trocas))) | 462 | if (stristr(strtr($v,$buscas,$trocas),strtr($palavra,$buscas,$trocas))) |
| 466 | { | 463 | { |
| 467 | - if (function_exists("mb_convert_encoding")) | ||
| 468 | - {$v = mb_convert_encoding($v,"UTF-8","ISO-8859-1");} | 464 | + $v = $this->converte($v); |
| 469 | $r[] = array("item" => $item,"valor" => $v); | 465 | $r[] = array("item" => $item,"valor" => $v); |
| 470 | $encontrado = "sim"; | 466 | $encontrado = "sim"; |
| 471 | } | 467 | } |
| @@ -676,10 +672,7 @@ $resolucao - Resolucao de busca. | @@ -676,10 +672,7 @@ $resolucao - Resolucao de busca. | ||
| 676 | } | 672 | } |
| 677 | if (count($resultados) > 0) | 673 | if (count($resultados) > 0) |
| 678 | { | 674 | { |
| 679 | - if (function_exists("mb_convert_encoding")) | ||
| 680 | - {$res = mb_convert_encoding($this->retornaI($listatemas,$resultados,$this->mapa),"UTF-8","ISO-8859-1");} | ||
| 681 | - else | ||
| 682 | - {$res = $this->retornaI($listatemas,$resultados,$this->mapa);} | 675 | + $res = $this->converte($this->retornaI($listatemas,$resultados,$this->mapa)); |
| 683 | return($res); | 676 | return($res); |
| 684 | } | 677 | } |
| 685 | else | 678 | else |
| @@ -847,7 +840,7 @@ $listaDeTemas - (opcional) Lista com os códigos dos temas que serão identificado | @@ -847,7 +840,7 @@ $listaDeTemas - (opcional) Lista com os códigos dos temas que serão identificado | ||
| 847 | {$nometmp = $layer->getMetaData("TEMA");} | 840 | {$nometmp = $layer->getMetaData("TEMA");} |
| 848 | else if ($layer->getMetaData("ALTTEMA") != "") | 841 | else if ($layer->getMetaData("ALTTEMA") != "") |
| 849 | {$nometmp = $layer->getMetaData("ALTTEMA");} | 842 | {$nometmp = $layer->getMetaData("ALTTEMA");} |
| 850 | - $nometmp = mb_convert_encoding($nometmp,"UTF-8","ISO-8859-1"); | 843 | + $nometmp = $this->converte($nometmp); |
| 851 | $final[] = array("nome"=>$nometmp,"resultado"=>$resultados[$tema]); | 844 | $final[] = array("nome"=>$nometmp,"resultado"=>$resultados[$tema]); |
| 852 | } | 845 | } |
| 853 | return $final; | 846 | return $final; |
| @@ -1216,7 +1209,7 @@ $listaDeTemas - (opcional) Lista com os códigos dos temas que serão identificado | @@ -1216,7 +1209,7 @@ $listaDeTemas - (opcional) Lista com os códigos dos temas que serão identificado | ||
| 1216 | if(trim($v) != "") | 1209 | if(trim($v) != "") |
| 1217 | { | 1210 | { |
| 1218 | $va = trim($v); | 1211 | $va = trim($v); |
| 1219 | - $va = mb_convert_encoding($va,"UTF-8","ISO-8859-1"); | 1212 | + $va = $this->converte($va); |
| 1220 | $n[] = array("alias"=>trim($t[0]),"valor"=>$va,"link"=>"","img"=>""); | 1213 | $n[] = array("alias"=>trim($t[0]),"valor"=>$va,"link"=>"","img"=>""); |
| 1221 | } | 1214 | } |
| 1222 | } | 1215 | } |
| @@ -1328,8 +1321,8 @@ $listaDeTemas - (opcional) Lista com os códigos dos temas que serão identificado | @@ -1328,8 +1321,8 @@ $listaDeTemas - (opcional) Lista com os códigos dos temas que serão identificado | ||
| 1328 | {$img = "<img src='".$shape->values[$itemimg[$conta]]."' //>";} | 1321 | {$img = "<img src='".$shape->values[$itemimg[$conta]]."' //>";} |
| 1329 | 1322 | ||
| 1330 | $arraytemp = array( | 1323 | $arraytemp = array( |
| 1331 | - "alias"=>mb_convert_encoding($itensdesc[$conta],"UTF-8","ISO-8859-1"), | ||
| 1332 | - "valor"=>mb_convert_encoding($val,"UTF-8","ISO-8859-1"), | 1324 | + "alias"=>$this->converte($itensdesc[$conta]), |
| 1325 | + "valor"=>$this->converte($val), | ||
| 1333 | "link"=>$link, | 1326 | "link"=>$link, |
| 1334 | "img"=>$img | 1327 | "img"=>$img |
| 1335 | ); | 1328 | ); |
| @@ -1347,5 +1340,27 @@ $listaDeTemas - (opcional) Lista com os códigos dos temas que serão identificado | @@ -1347,5 +1340,27 @@ $listaDeTemas - (opcional) Lista com os códigos dos temas que serão identificado | ||
| 1347 | {$resultado[] = " ";} | 1340 | {$resultado[] = " ";} |
| 1348 | return $resultado; | 1341 | return $resultado; |
| 1349 | } | 1342 | } |
| 1343 | + /* | ||
| 1344 | + Function: converte | ||
| 1345 | + | ||
| 1346 | + Converte uma string de ISO-8859-1 para UTF-8 | ||
| 1347 | + | ||
| 1348 | + Parametro: | ||
| 1349 | + | ||
| 1350 | + $texto - string que será convertida | ||
| 1351 | + | ||
| 1352 | + Return: | ||
| 1353 | + | ||
| 1354 | + {string} | ||
| 1355 | + */ | ||
| 1356 | + function converte($texto) | ||
| 1357 | + { | ||
| 1358 | + if (function_exists("mb_convert_encoding")) | ||
| 1359 | + { | ||
| 1360 | + if (!mb_detect_encoding($texto,"UTF-8",true)) | ||
| 1361 | + {$texto = mb_convert_encoding($texto,"UTF-8","ISO-8859-1");} | ||
| 1362 | + } | ||
| 1363 | + return $texto; | ||
| 1364 | + } | ||
| 1350 | } | 1365 | } |
| 1351 | ?> | 1366 | ?> |
| 1352 | \ No newline at end of file | 1367 | \ No newline at end of file |