
July 27th, 2011, 11:04 PM
|
 |
Web Developer
|
|
|
|
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?
PHP Code:
<?php
$str = 'test ad <a href="www.google.com">Google</a> test ad
<a href=\'www.gmail.com\'>Gmail</a> test ad
<a href="http://www.google.com">Google</a>';
$output = preg_replace('@(href="|href=\'[^http://])@','$1http://',$str);
echo $output;
?>
__________________
I will try my best !!!
Last edited by web_developer : July 27th, 2011 at 11:05 PM.
Reason: Forget to PHP quote
|