Revision: 11266
Updated Code
at January 29, 2009 13:33 by sveggiani
Updated Code
/**
* Rewrite strings to be URL/SEO friendly
* @param string $text
* @return string
*/
function slugify($text) {
// Map thanks to CakePHP
$map = array(
'/à|á|å|â/' => 'a',
'/è|é|ê|?|ë/' => 'e',
'/ì|ÃÂ|î/' => 'i',
'/ò|ó|ô|ø/' => 'o',
'/ù|ú|?|û/' => 'u',
'/ç/' => 'c',
'/ñ/' => 'n',
'/ä|æ/' => 'ae',
'/ö/' => 'oe',
'/ü/' => 'ue',
'/�/' => 'Ae',
'/�/' => 'Ue',
'/�/' => 'Oe',
'/�/' => 'ss',
'/[^\w\s]/' => ' ',
);
$text = preg_replace(array_keys($map), array_values($map), $text);
$text = preg_replace('/[^-a-zA-Z0-9&\s]/i', '', $text);
$text = trim(strtolower($text));
$text = str_replace(array('-', ' ', '&'), array('_', '-', 'and'), $text);
$text = urlencode($text);
return $text;
}
Revision: 11265
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at January 29, 2009 13:26 by sveggiani
Initial Code
/**
* Rewrite strings to be URL/SEO friendly
* @param string $text
* @return string
*/
function slugify($text) {
// Map thanks to CakePHP
$map = array(
'/à |á|å|â/' => 'a',
'/è|é|ê|?|ë/' => 'e',
'/ì|Ã|î/' => 'i',
'/ò|ó|ô|ø/' => 'o',
'/ù|ú|?|û/' => 'u',
'/ç/' => 'c',
'/ñ/' => 'n',
'/ä|æ/' => 'ae',
'/ö/' => 'oe',
'/ü/' => 'ue',
'/Ä/' => 'Ae',
'/Ü/' => 'Ue',
'/Ö/' => 'Oe',
'/ß/' => 'ss',
'/[^\w\s]/' => ' ',
);
$text = preg_replace(array_keys($map), array_values($map), $text);
$text = preg_replace('/[^-a-zA-Z0-9&\s]/i', '', $text);
$text = trim(strtolower($text));
$text = str_replace(array('-', ' ', '&'), array('_', '-', 'and'), $text);
$text = urlencode($text);
return $text;
}
Initial URL
http://www.milesj.me/blog/read/15/5-custom-basic-php-string-functions
Initial Description
Esta versión, a diferencia de mi otra función reemplaza las vocales acentuadas y otros caracteres
Initial Title
generates slug or permalink from a given string
Initial Tags
Initial Language
PHP