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));