Function to remove unwanted characters from your dynamically generated URLs
function sanitizeURL ($URL, $tolower = true){
$find = array("/\s+/", "/[-]+/", "/\\\/", "/'/");
$replace_with = array("-", "-", "", "");
$URL = preg_replace($find, $replace_with, $URL);
if($tolower){
$URL = strtolower($URL);
}
return strtolower($URL);
}
Demo
if i send
$url = 'http://www.abc.com/'.NormalizeURL('names in Advertising /Entertainment/ Media/ Publishing at abc.com');
echo $url;
OUTPUT
http://www.abc.com/names-in-advertising-/entertainment/-media/-publishing-at-abc.com
No comments:
Post a Comment