note 89726 added to function.str-replace
| From: | DanyAlejandroCabrera at osu1 dot php dot net | Date: | Fri, 20 Mar 2009 14:03:26 +0000 |
| Subject: | note 89726 added to function.str-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-152208@lists.php.net to get a copy of this message | ||
This is a function that filters a filename for nicer URLs. It doesn't turn the whole filename
to lowercase (easy mod):
/*
* 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
----
Server IP: 69.147.83.197
Probable Submitter: 190.159.250.153
----
Manual Page -- http://www.php.net/manual/en/function.str-replace.php
Edit -- https://master.php.net/note/edit/89726
Del: integrated -- https://master.php.net/note/delete/89726/integrated
Del: useless -- https://master.php.net/note/delete/89726/useless
Del: bad code -- https://master.php.net/note/delete/89726/bad+code
Del: spam -- https://master.php.net/note/delete/89726/spam
Del: non-english -- https://master.php.net/note/delete/89726/non-english
Del: in docs -- https://master.php.net/note/delete/89726/in+docs
Del: other reasons-- https://master.php.net/note/delete/89726
Reject -- https://master.php.net/note/reject/89726
Search -- https://master.php.net/manage/user-notes.php