Pages

Friday, December 9, 2011

How to replace all spaces in url

Url now should be seo friendly as possible to make it indexed by google quickly. Therefore, many urls use the article title of which is of course could contain spaces. Then how to replace spaces with certain characters in the url ??.
The following script can be used :
$url = strtolower(str_replace(array('  ', ' '), '-', preg_replace('/[^a-zA-Z0-9 s]/', '', trim($string))));
Notes :
Those script using php
Replace '-' with any character as you wish
Those script convert all cases to lower

No comments:

Post a Comment

Don't Forget To Join Our Community
×
Widget