Posted By

tylerhall on 06/06/07


Tagged

php textmate String slug


Versions (?)

Who likes this?

19 people have marked this snippet as a favorite

samuraicoder
damarev
imbuez
basicmagic
n00ge
chucktrukk
romanos
tikitakfire
troynt
nb109
sultano
digiteyes
sveggiani
mfigge
lfcortes
prit
svemoguci
itsmeameer
tux-world


Convert String to Slug


 / Published in: PHP
 

This filters a string into a "friendly" string for use in URL's. It converts the string to lower case and replaces any non-alphanumeric (and accented) characters with dashes.

  1. function slug($str)
  2. {
  3. $str = strtolower(trim($str));
  4. $str = preg_replace('/[^a-z0-9-]/', '-', $str);
  5. $str = preg_replace('/-+/', "-", $str);
  6. return $str;
  7. }

Report this snippet  

You need to login to post a comment.