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.example.com/lcdetail.php?akey=e1725">http://www.example.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.example.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.
Well, I just modified your lookbehind path to (?<!href="|">)
to avoid the link inside the tags...
So use :
function processString($s){
return preg_replace('@(?<!href="|">)(https?:\/\/[\w\-\.!~?&=+\*\'(),\/]+)((?!\<\/\a\>).)*@i','<a href="$1">$1</a>',$s);
}