function slug($string) — (gyural)


/ Published in: PHP
Save to your folder(s)

Slug.


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.