Posted By

ibomb on 04/18/08


Tagged

urlvalid urlregex


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

ibomb
ZiBoX


String to valid url generator


 / Published in: PHP
 

URL: http://www.dluxagency.com

  1. $string = "1@-This 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"

Report this snippet  

You need to login to post a comment.