Create a URL from a string of text with PHP and mod_rewrite

24 November 2011

Quite often when developing big web apps you may need to use mod_rewrite to generate SEO friendly URLs from a string of text, Very similar to the way Word press generates URLs for blog posts.


The Code

Below is the function which will remove all the spaces and special characters from a string and convert it to lowercase making sure its formated ready to be used as a page URL.

function create_slug($string){
   $string = preg_replace( '/[
Sumber : Jasa Pembuatan Website dan Sistem Informasi http://klatenweb.com
Selengkapnya : http://klatenweb.com/read/2011/11/24/749/Create-a-URL-from-a-string-of-text-with-PHP-and-mod_rewrite.html