Create A URL Slug With PHP – WortGepresst



STARTSEITE MULTIMEDIA WORTGEPRESST FAMILIENBANDE BOOKMARK PRIVACY


Create A URL Slug With PHP

Having a user friendly URL is user important not just for SEO but also to help the visitors know that the website they are on is correct. If you have spaces in your URL they will be replaced by %20 so if you are linking to the page.

The browser would actual render this URL as

As you can see this isn’t the most user friendly URL so you need to be able to replace the spaces with hyphens. Here is a PHP snippet that will replace all spaces with a hyphen.

 

Extended URL Slug Version

Here is an extended version of the URL slug function. This will take care of any characters which have accents and will also catch double hyphens in the URL and replace it will just the one hyphen.


Source://gist.github.com/2912227
Font Resize
Contrast
Zur Werkzeugleiste springen