How to save php files with utf8 characters?

0

When I name a php file with utf8 characters, for example 'ççáá.php' the local server does not open the file.

I really need utf8 names to name these files, but you can do some sort of conversion . That is to get a utf8 name , convert it to a file name that the server recognizes, and save the file with the converted name. After that get the converted name and turns it into utf8 to use in the code. In other words, the process must be reversible .

What is the function or algorithm to accomplish this task?

Obs: I tried to use utf8_encode () / utf8_decode () but both generate filenames that the local server also does not recognize.

    
asked by anonymous 04.04.2018 / 14:49

1 answer

1
  

Since you only need to convert ccaa to ccaa, according to your comment, I'll post the link code here

A secure replacement of accented characters can be performed using the strtr () function called only two arguments. strtr( $nomeArquivo, $indesejado_array );

$nomeArquivo = "ççáá.php";
$indesejado_array = array(    'Š'=>'S', 'š'=>'s', 'Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E',
                            'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U',
                            'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss', 'à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c',
                            'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o',
                            'ö'=>'o', 'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y' );

$nomeArquivo = strtr( $nomeArquivo, $indesejado_array );

example running on ideone

    
04.04.2018 / 19:24