我有php页面的url,其中包括我以前的url与编码字符串的路径。但是当打开这个url时出现错误,因为有一些指定的字符,比如空格....
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