July 27th, 2011, 11:04 PM
Want to append http:.// in url
I have one long description string which have some URL included, Among it some url have http:// and some have not so I want to add http:// in those URL. And for that I have write below Regex but it's not working.. can anyone help me out what should I have to do?
$str = 'test ad <a href="www.google.com">Google</a> test ad
<a href=\'www.gmail.com\'>Gmail</a> test ad
$output = preg_replace('@(href="|href=\'[^http://])@','$1http://',$str);
Last edited by web_developer; July 27th, 2011 at 11:05 PM.
Reason: Forget to PHP quote
I will try my best !!!
July 28th, 2011, 11:46 AM
Generally one can produce better results if one actually learns the material as opposed to just guessing.
preg_replace('#href=["\'](?![a-z]+://)#i', '$0http://', $str)