Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.