Make string into post slug


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



Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. function str2url($title,$sep = "-"){
  4. $exclude = array("!","@","#","$","%","^","&","*","(",")","=","{","}","[","]","|","\\","/","?","<",">","~","`","_","+","=","-");
  5. $pieces = explode(' ',str_replace($exclude,"",strtolower($title)));
  6. $output = NULL;
  7. foreach($pieces as $key => $val){
  8. if($pieces[$key+1] == NULL){
  9. $sep = NULL;
  10. }
  11. $output .= $val.$sep;
  12. }
  13. return $output;
  14. }
  15.  
  16. echo str2url("Evan Walsh Rocks"); // returns evan-walsh-rocks
  17.  
  18. ?>

URL: http://nothingconcept.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.