PHP - Add link to a URL in a string if not present
Lets say i had a string as in $str ::
$str = "Test,
Here\'s an interesting in-house litigation position with JPMorgan Chase in
New York I thought you might be interested inL
<a
href="http://www.xxx.com/lcdetail.php?akey=e1725">http://www.xxx.com/lcdetail.php?akey=e1725</a>
They are not using recruiters to fill this job, so if you are interested
you can just apply directly.
http://www.xxx.com/lcdetail.php?akey=e1725
Cordially
--Harrison";
Now i want to added tag to the links whom tag is not present.
I had used this function but not returning desired value.
function processString($s){
return
preg_replace('@(?<!href=")(https?:\/\/[\w\-\.!~?&=+\*\'(),\/]+)((?!\<\/\a\>).)*@i','<a
href="$1">$1</a>',$s);
}
My requirement is NOT to ADD anchor tag in link if it is present and ADD
to those which haven't.
Thanks.
No comments:
Post a Comment