What I want
If the URL in the string contains a .jpg
at the end of the URL (not the string) then it should make an image from it with preg_replace
else make a normal link.
so for example:
If I have http://www.example.com/images/photo.jpg
then it should replace with:
<img src="http://www.example.com/images/photo.jpg" alt="http://www.example.com/images/photo.jpg">
The problem:
The URL is replaced with a link in any way and my regex isn't working :( .
What I have tried:
$content = preg_replace("/(http:\/\/[^\s]+(?=\.jpg))/i","<img src=\"$1\" alt = \"$1\"></img>",$content);
$content = nl2br(preg_replace("/(http:\/\/[^\s]+(?!\.jpg))/m", "<a href=\"$1\" rel=\"nofollow\" target=\"blank\" title=\"$1\" class=\"news-link\">$1</a>", $content));
I think you used the lookahead operator when you wanted lookbehind. You could change
(?=\.jpg)
to(?<=\.jpg)
but there are other, cleaner regex's I'm sure others will post.This worked for me.
In the figure above, router R1 has two point-to-point . ';
Suyash
Try this
You don't need lookaround. Just go with