note 89726 deleted from function.str-replace by philip

From: 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

« previous php.notes (#161440) next »