2015-09-14 69 views
1

我有一个包含我以前的URL与编码字符串的路径的url网页。但它有错误时,打开这个网址,因为一些特定的字符,如空间....php的URL编码(previousUrl)问题

url="www.xxxx.com/home/".encode($previousUrl) 
+0

你可能想尝试PHP的[建立一个url函数](http://php.net/manual/en/function.http-build-url.php) – Terminus

+0

可以请你分享previousUrl。 –

回答

1

尝试清洁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 
+0

似乎不能$ PrevUrl需要重定向回到以前的网址。如果我修改previousUrl,它是否仍然会正确重定向? –

+0

干净的功能只会从提供的网址中删除无效的字符,如果url是一个有效的路径,如果您的重定向代码是有效的,它将重定向 –

+0

嗨,我已经使用你的情况。这是不正确的,因为当我使用清洁的网址重定向到此网址。它是无法识别的,因为我看到这与以前的Url字符串不同。 –