Jump to content

Catch image from text


vividona

Recommended Posts

How can I catch image bbcode from the first point of text.

 

eg

 

[img=http://www.xxxxxxx.xxxxx/xxxxx.jpg] text here  text here  text here  text here  text here  text here  text here  text here  text here  text here  text here  text here  text here  text here  text here  text here  text here  text here  text here  text here  text here  text here  text here  text here  text here  text here  text here 

Link to comment
https://forums.phpfreaks.com/topic/240499-catch-image-from-text/
Share on other sites

You want the image url from it or?

 

$str = '[img=http://www.xxxxxxx.xxxxx/xxxxx.jpg] text here  text here';
preg_match_all('/\[img\]http://(.*)\[\/img\]/', $str, $results);
echo '<pre>' . print_r($results) . '</pre>';

 

Hi, thank you so much, it works fine but the output is


[img=http://www.xxxxxxx.xxxxx/xxxxx.jpg]http://www.xxxxxxx.xxxxx/xxxxx.jpg

 

how can I made it just

 


[img=http://www.xxxxxxx.xxxxx/xxxxx.jpg]

I just tested it and it gives just fine output:

 

Array ( [0] => Array ( [0] => [img=http://www.xxxxxxx.xxxxx/xxxxx.jpg] ) [1] => Array ( [0] => http://www.xxxxxxx.xxxxx/xxxxx.jpg ) ) 

 

Just use the first array element to get the tags with the url. Or use the second array element to get only the URL. I am pretty sure you are looping each array element throught and echoing them.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.