Reputation: 295
How can i use ereg to replace URL of images with tag.
My images URL have two starts embraced like this **http://myimageslink/photo.jpg**
i want to convert to <img src="http://myimageslink/photo.jpg"></img>
I use ** embrace because when don't have ** https://www.google.com/?gws_rd=ssl
i will convert to <a href="https://www.google.com/?gws_rd=ssl">https://www.google.com/?gws_rd=ssl</a>
like this.
The code below doesn't work i got like this <img src="**http://myimageslink/photo.jpg**"></img>
$text = ereg_replace("**[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]**",
"<img src=\"\\0\"></img>", $str);
but I want the results like this.
<img src="http://myimageslink/photo.jpg"></img>
And this the real example.
$text = 'This is first photo **http://myimageslink/photo.jpg**<br />
This is second photo **http://myimageslink/photo.jpg**';
$text = ereg_replace("**[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]**",
"<img src=\"\\0\"></img>", $text);
So, $text should be
$text = 'This is first photo <img src="http://myimageslink/photo.jpg"><br />
This is second photo </img><img src="http://myimageslink/photo.jpg"></img>';
Upvotes: 0
Views: 173