Posted By

mscribellito on 12/07/10


Tagged


Versions (?)

Humanize a String


 / Published in: PHP
 

  1. function humanize($str) {
  2.  
  3. $str = trim(strtolower($str));
  4. $str = preg_replace('/[^a-z0-9\s+]/', '', $str);
  5. $str = preg_replace('/\s+/', ' ', $str);
  6. $str = explode(' ', $str);
  7.  
  8. $str = array_map('ucwords', $str);
  9.  
  10. return implode(' ', $str);
  11. }

Report this snippet  

You need to login to post a comment.