Hey people how can I extract an image from text like this:
bla bla bla bl [IMG2;DanilaCarneiro_capa2.jpg;D], bla bla bla , [IMG2;abcsd.jpg;E], bla bla
What I did:
preg_match_all('![IMG2;[a-z0-9\-\.\/]+\.(?:jpeg|png|gif)!Ui' , $value->CORPO , $matches);
but it just give the last name for example DanilaCarneiro_capa2.jpg
give -> capa2.jpg
, i need DanilaCarneiro_capa2.jpg
and this [IMG2;DanilaCarneiro_capa2.jpg;D]
.
Is very difficult?
Try this:
preg_match_all('!\[IMG2;(.*?(?:jpg|png|gif))!i', $value->CORPO , $matches);
You can use this pattern:
$pattern = '~\[IMG2;\K[^];]++~i';
preg_match_all($pattern, $value->CORPO, $matches);
If you want to check the extension:
$pattern = '~\[IMG2;\K[^];]+\.(?:jpeg|png|gif)(?=[];])~i';
You might want to escape the square bracket
\[IMG2;[a-z0-9\-./]+\.(?:jpeg|png|gif)