Posted By

julioantuneztarin on 06/17/11


Tagged

php format regexp strings


Versions (?)

Underscore strings


 / Published in: PHP
 

URL: http://snipplr.com/view/4848/underscore-strings/

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

Report this snippet  

You need to login to post a comment.