note 89726 deleted from function.str-replace by philip
| From: | philip@php.net | Date: | Wed, 07 Oct 2009 07:55:23 +0000 |
| Subject: | note 89726 deleted from function.str-replace by philip | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-161440@lists.php.net to get a copy of this message | ||
Note Submitter: Dany Alejandro Cabrera
----
This is a function that filters a filename for nicer URLs. It doesn't turn the whole filename
to lowercase (easy mod):
<?php
/*
* Devuelve el nombre del archivo filtrado de la siguiente manera:
* Los espacios sustituidos por '-'
* Los acentos se quitan de las vocales
* 'n' en vez de 'ñ'
* Cualquier otro caracter especial diferente de ('_', '-', '.') se
elimina
*/
function preparar_nom_archivo($nom_archivo)
{
$arr_busca = array('
','á','à ','â','ã','ª','Ã','Ã',
'Ã','Ã',
'é','è','ê','Ã','Ã','Ã','Ã','ì','î','Ã',
'Ã','Ã','ò','ó','ô',
'õ','º','Ã','Ã','Ã','Ã','ú',
'ù','û','Ã','Ã','Ã','ç','Ã','Ã','ñ');
$arr_susti =
array('-','a','a','a','a','a','A','A',
'A','A','e','e','e','E','E','E','i','i','i','I','I',
'I','o','o','o','o','o','O','O','O','O','u','u','u',
'U','U','U','c','C','N','n');
$nom_archivo = trim(str_replace($arr_busca, $arr_susti, $nom_archivo));
return ereg_replace('[^A-Za-z0-9\_\.\-]', '', $nom_archivo);
}
?>
(you may delete the line breaks in the arrays) Sorry for the spanish. In english: Substitutes spaces
with '-', accents turn into vocals, 'ñ' to 'n', deletes weird
characters except ('_', '-', '.').
Cheers