我有一個包含我以前的URL與編碼字符串的路徑的url網頁。但它有錯誤時,打開這個網址,因爲一些特定的字符,如空間....php的URL編碼(previousUrl)問題
url="www.xxxx.com/home/".encode($previousUrl)
我有一個包含我以前的URL與編碼字符串的路徑的url網頁。但它有錯誤時,打開這個網址,因爲一些特定的字符,如空間....php的URL編碼(previousUrl)問題
url="www.xxxx.com/home/".encode($previousUrl)
嘗試清潔URL中使用以下功能:
function clean($string) {
$string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
$string = preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
return preg_replace('/-+/', '-', $string); // Replaces multiple hyphens with single one.
}
$encUrl=clean($previousUrl); //pass the url to clean
似乎不能$ PrevUrl需要重定向回到以前的網址。如果我修改previousUrl,它是否仍然會正確重定向? –
乾淨的功能只會從提供的網址中刪除無效的字符,如果url是一個有效的路徑,如果您的重定向代碼是有效的,它將重定向 –
嗨,我已經使用你的情況。這是不正確的,因爲當我使用清潔的網址重定向到此網址。它是無法識別的,因爲我看到這與以前的Url字符串不同。 –
你可能想嘗試PHP的[建立一個url函數](http://php.net/manual/en/function.http-build-url.php) – Terminus
可以請你分享previousUrl。 –