Leave urls containing special characters

hi all

i m creating google sitemap and some of site url’s containg special characters


Extreme�-Pro�-SDHC�-UHS

i want to leave these urls which contain special characters and create sitemap with rest of the urls.

what function should i use leave these urls.

vineet

Just URL encode those URLs in your XML sitemaps. Should solve the problem :slight_smile:

you could white list characters that you want to allow or blacklist the special character you don’t want to include.

untested code ahead



$pattern1 = '([A-Za-z0-9]+)'; //allow only letters and numbers
$pattern2 = '([^!@#\\$%\\^&\\*])'; //exclude !@#$%^&* characters

//example
if( preg_match($pattern1, $url, $matches) ){
    //add to site map
}

I’m no expert on regular expressions so I’m not entire sure if the code will work but this is one good way of looking for specific characters in a string. alternatively you could use strstr($url, $char) to look for it.

thanks charles

your code helped me

vineet