String to valid url generator


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



Copy this code and paste it in your HTML
  1. $string = "[email protected] is a Random string£";
  2.  
  3. //not allowed chars
  4. $pattern = '/[^\w\s]+/';
  5. $replacement = '';
  6. $url = preg_replace($pattern, $replacement, $string);
  7.  
  8. //change the space with -
  9. $not_allowed = array(" ");
  10. $url = strtolower(str_replace($not_allowed, "-", $url));
  11.  
  12. // result
  13. $url = "1-this-is-a-random-string"

URL: http://www.dluxagency.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.