note 77247 deleted from function.mb-ereg-replace by nlopess
| From: | nlopess@php.net | Date: | Sat, 01 Sep 2007 12:06:02 +0000 |
| Subject: | note 77247 deleted from function.mb-ereg-replace by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-130014@lists.php.net to get a copy of this message | ||
Note Submitter: Michal Zalewski
----
function makeSeoName($name, $length = 64){
$name = trim($name);
//convert to lower case
$name = mb_convert_case($name, MB_CASE_LOWER, 'utf-8');
//replace space and other blank chars to "-"
$name = mb_ereg_replace('[[:blank:]]', '-', $name);
//replace monalpha-numeric and "-" to nothing
$name = mb_ereg_replace('[^[:alnum:]\-]', '', $name);
//replace double "-" to one "-"
$name = mb_ereg_replace('\-+', '-', $name);
//substring
$name = mb_substr($name, 0, $length, 'utf-8');
return $name;
}
$string = '[EN] This is example [PL]
Ä
ÄÄÄÄÄÅÅÅÅóÃÅÅżŻźŹ [RU]
Хиддинк [DE] Spaà Ernähr';
echo makeSeoName($string, 64);