24
I have this function already too old to "clean" the contents of a variable:
Function
function sanitizeString($string) {
// matriz de entrada
$what = array( 'ä','ã','à','á','â','ê','ë','è','é','ï','ì','í','ö','õ','ò','ó','ô','ü','ù','ú','û','À','Á','É','Í','Ó','Ú','ñ','Ñ','ç','Ç',' ','-','(',')',',',';',':','|','!','"','#','$','%','&','/','=','?','~','^','>','<','ª','º' );
// matriz de saída
$by = array( 'a','a','a','a','a','e','e','e','e','i','i','i','o','o','o','o','o','u','u','u','u','A','A','E','I','O','U','n','n','c','C','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_' );
// devolver a string
return str_replace($what, $by, $string);
}
Utilizing
<?php
$pessoa = 'João dos Santos Videira';
$pastaPessoal = sanitizeString($pessoa);
// resultado
echo $pastaPessoal; // Joao_dos_Santos_Videira
?>
Being an old function, at the time of its creation make a substitution of a character A by B was the best option, but do maintenance to an input matrix and an output matrix is not easy and back and forth there appears an unforeseen scenario.
With the evolution of PHP, how to refactor this function making use of own language solutions or easier to maintain?
Note referring to the tag Sanitize: I couldn’t translate or find an existing tag for this word.
– Zuul
Mark an answer as accepted if one of them is for you.
– user622
Sanitize means to sanitize or sanitize. But it’s kind of ugly to translate for this, rs! Let’s really.
– user622