Funcion para limpiar urls, fiendly urls
- February 6th, 2010
- Posted in Programacion . Web
- Write comment
Bueno, esta funcion limpia la url de los caracteres muy extraños y espacios.
El fin de postear esto, es que no se me olvide esta funcion.
function limpia_url( $string , $space="-" )
{
$currentMaximumURLLength = 100;
if (function_exists('iconv'))
{
$string = @iconv('UTF-8', 'ASCII//TRANSLIT', $string);
}
$string = preg_replace("/[^a-zA-Z0-9 -]/", "", $string);
$string = strtolower($string);
$string = str_replace(" ", $space, $string);
if (strlen($string) > $currentMaximumURLLength)
{
$string = substr($string, 0, $currentMaximumURLLength);
}
$string = preg_replace('/_$/i', '', $string);
$string = preg_replace('/^_/i', '', $string);
return $string;
}
Algo como esto:
Trackers progreso en Diseño Web: Ejemplos y Buenas Prácticas
Se convierte en algo como esto:
trackers-progreso-en-diseno-web-ejemplos-y-buenas-practicas
No comments yet.