Posted By

sorehead on 10/09/06


Tagged


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

imbuez
blakeb
Slashman
vali29


Convert string to underscore_name


 / Published in: PHP
 

  1. <?php
  2. /* Convert string to underscore_name
  3.  
  4. Converts "My House" to "my_house".
  5. Converts " Peter's nice car " to "peters_nice_car".
  6. Converts "_88" to "88" */
  7.  
  8. function string_to_underscore_name($string)
  9. {
  10. $string = preg_replace('/[\'"]/', '', $string);
  11. $string = preg_replace('/[^a-zA-Z0-9]+/', '_', $string);
  12. $string = trim($string, '_');
  13. $string = strtolower($string);
  14.  
  15. return $string;
  16. }
  17. ?>

Report this snippet  

You need to login to post a comment.