英文:
代码如下 |
|
function tourl($str) {
$str = preg_replace('/[^a-zA-Z0-9]+/', '-', $str);
$str = trim($str, '-');
return strtolower($str);
}
代码如下 |
|
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);
}
代码如下 |
|
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);
}
|
|
除了上面方法php提供了urlencode()、urldecode()、rawurlencode()、rawurldecode()函数了,利用它就可以直接转换了这个就不介绍了。
http://www.bkjia.com/PHPjc/737699.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/737699.htmlTechArticle英文: 代码如下 function tourl($str) { $str = preg_replace('/[^a-zA-Z0-9]+/', '-', $str); $str = trim($str, '-'); return strtolower($str); } 包含特殊字符: 代码如下...