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

Abe on 01/30/08


Tagged

url String name nice underscore


Versions (?)


Who likes this?

5 people have marked this snippet as a favorite

adix
stphnclysmth
romanos
Dingdong
tikitakfire


Underscore Strings


Published in: PHP 


You can use it with 'Nice URLs' http://snipplr.com/view/4562/nice-urls-php-htaccess/

  1. <?php
  2. function string_to_underscore_name($string) {
  3. $string = preg_replace('/[\'"]/', '', $string);
  4. $string = preg_replace('/[^a-zA-Z0-9]+/', '_', $string);
  5. $string = strtolower(trim($string, '_'));
  6. return $string;
  7. }
  8. echo string_to_underscore_name("13: inside movie films```''''---\//\Bye!?");
  9. //Output: 13_inside_movie_films_bye
  10. ?>

Report this snippet 

You need to login to post a comment.