July 28th, 2011, 12:04 AM
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 28th, 2011 at 12:05 AM.
Reason: Forget to PHP quote
I will try my best !!!
July 28th, 2011, 12:46 PM
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)