Posted By

federicoq on 02/06/13


Tagged


Versions (?)

function slug($string) — (gyural)


 / Published in: PHP
 

Slug.

  1. <?
  2. function slug($phrase, $maxLength = 50) {
  3. $result = strtolower($phrase);
  4. $result = preg_replace("/[^a-z0-9\s-]/", "", $result);
  5. $result = trim(preg_replace("/[\s-]+/", " ", $result));
  6. $result = trim(substr($result, 0, $maxLength));
  7. $result = preg_replace("/\s/", "-", $result);
  8. return $result;
  9. }
  10. ?>

Report this snippet  

You need to login to post a comment.