Return to Snippet

Revision: 50428
at August 21, 2011 01:35 by Entherman


Initial Code
# Fix the URL:
$url = preg_replace('/((http:\/\/)?(www\.)?([\w\d-]*?\.)(\w{2,4})/?)/i', 'http://www.$4$5', $d[0]);

From: 
 google.com 
 www.google.com 
 google.com/ 
 http://google.com 
 http://www.google.com 
 http://www.google.com/ 

To:
 http://www.google.com 
 http://www.google.com 
 http://www.google.com 
 http://www.google.com 
 http://www.google.com 
 http://www.google.com

Initial URL
http://www.themer.me/blog/scripting/460/clean-url-with-regex

Initial Description
Useful when using user-submitted URLs

Initial Title
Clean User Submitted URL's

Initial Tags
regex

Initial Language
PHP