We Recommend

Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems
Wicked Cool PHP contains a wide variety of scripts to process credit cards, check the validity of email addresses, template HTML, and serve dynamic images and text.


Posted By

section31 on 09/16/08


Tagged

clean urls


Versions (?)


Who likes this?

3 people have marked this snippet as a favorite

jdstraughan
luman
ithinksometimes


Clean URL String


Published in: PHP 


  1. function get_clean_url_string($str) {
  2. $search = array(
  3. '/\s+/i',
  4. '/(-|_)(-|_)*/',
  5. '/[^a-z0-9_-]/i'
  6. );
  7. $replace = array(
  8. '-',
  9. '$1',
  10. ''
  11. );
  12. return preg_replace($search, $replace, trim($str));
  13. }

Report this snippet 

You need to login to post a comment.