Search for image tags within PHP string

3

I have a string of type:

 Veja o logotipo do PHP: <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/31/Webysther_20160423_-_Elephpant.svg/2000px-Webysther_20160423_-_Elephpant.svg.png">

I need to get the path of the image in the string. The string can give you multiple images.

How can I get exactly the path of the images and remove the rest of the string?

    
asked by anonymous 17.11.2016 / 18:20

1 answer

3

You can do something similar to this response from SOEN :

$doc = new DOMDocument();
$doc->loadHTML($string_com_img);
$imageTags = $doc->getElementsByTagName('img');

$srcs = [];

foreach($imageTags as $tag) {
    $srcs[] = $tag->getAttribute('src');
}

This question is also very similar to your problem. It's worth a look:

Get a value that is within a on another site using PHP

    
17.11.2016 / 18:22