我需要一个能帮我创建这样一个网址的人http://www.saqaw.com/AllAds/Other-ladys-Fashion/page=1
但不喜欢这个
http://www.saqaw.com/AllAds/?Ad=Other%20ladys%20Fashion&page=1
答案 0 :(得分:0)
这是一个非常笼统的问题,但快速网址解析器可能会对您有所帮助:
$url = "http://www.saqaw.com/AllAds/?Ad=Other%20ladys%20Fashion&page=1";
$url = parse_url($url);
$queries = explode("&", $url['query']);
$newURL = $url['host'] . $url['path'];
foreach ($queries as $query) {
$queryContent = explode("=", $query);
$queryContent[0] == "Ad"? $newURL .= str_replace("%20", "-", $queryContent[1]):$newURL .= "/".$query;
}
echo $newURL;
结果
www.saqaw.com/AllAds/Other-ladys-Fashion/page=1
但是,如果您要查找更通用的URL解析,可以使用以下脚本:
$url = "http://www.saqaw.com/AllAds/?Ad=Other%20ladys%20Fashion&page=1";
$url = parse_url($url);
$queries = explode("&", $url['query']);
$newURL = $url['host'] . $url['path'];
foreach ($queries as $query) {
$queryContent = explode("=", $query);
$newURL .= $queryContent[0] . "/" . str_replace("%20", "-", $queryContent[1]) . "/";
}
echo $newURL;
结果
www.saqaw.com/AllAds/Ad/Other-ladys-Fashion/page/1/
但是上述脚本是快速修复的,不包括安全性或脚本注入。