User-Friendly urls (slugs)

Submitted by:Jhon Brain

Date added:04 October, 2012

Category:PHP

Turn a string into a readable url

Tags: user friendly urls

Code Snippet:

# slug.php

<?php
function create_slug($string){
$slug=preg_replace('/[^A-Za-z0-9-]+/', '-', $string);
return $slug;
}



<?php
$title = "Best PHP scripts ever";
$slug = create_slug($title);

echo $slug; // best-php-scripts-ever



 
 

Comments