英文:
function tourl($str) {
$str = preg_replace('/[^a-zA-Z0-9]+/', '-', $str);
$str = trim($str, '-');
return strtolower($str);
}
包含特殊字符:
function strtourl($str) {
$str = htmlentities($str, ENT_QUOTES, "UTF-8");
$str = preg_replace('/&([a-z]{1,2})(?:acute|lig|grave|ring|tilde|uml|cedil|caron);/i','\1',$str);
$str = html_entity_decode($str, ENT_QUOTES, "UTF-8");
$str = preg_replace('/[^a-z0-9]+/i', '-', $str);
return strtolower($str);
}
标签:none