I have this function 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);
}
Use
<?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 making a substitution of a character A by B was the best option, but doing 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 by making use of language solutions or easier to maintain?