string to url compatible


/ Published in: PHP
Save to your folder(s)

remove multiple spaces and replace with underscore


Copy this code and paste it in your HTML
  1. function stringUrlFormat($str){
  2. $underscore = chr(95);
  3. $space = chr(32);
  4. // compress multiple spaces
  5. $count = 1;
  6. while($count){
  7. $str = str_replace(' ', $space, $str, $count);
  8. }
  9.  
  10. $str = str_replace($space, $underscore, $str);
  11. return $str;
  12. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.