How to pull out of the text all src of images in php?

There is a line - text + image
<p>Here the text <img alt src="https://nailsoftheday.com/upload/_images/images/26.jpg" style="height:437px; width:437px"> arbitrary text</p>
<p>arbitrary text <img alt src="https://nailsoftheday.com/upload/_images/images/placeholder-3.jpg" style="height:800px; width:1280px"> random text random text</p>

You need to pull all the src of images, and how to do it?
June 14th 19 at 20:25
2 answers
June 14th 19 at 20:27
Solution
Good afternoon.
You can use regular expression or try a library for parsing, for example phpquery.
The regular expression might look so.
June 14th 19 at 20:29
$content = file_get_contents('img.php'); // Prisvoeniem variable $content the html page

preg_match_all('/src=\"(.*?)\"/', $content, $array); // choose from the $content variable all src

foreach ($array[1] as $item){
var_dump($item); // print the net links to pictures
}
This decision saw earlier, but for some reason we get a result like this
0
"src="https://nailsoftheday.com/upload/_images/images/26.jpg""
"src="https://nailsoftheday.com/upload/_images/images/pl...""
"src="https://nailsoftheday.com/upload/_images/images/pl...""

As you can see in the end of each line an extra quotation mark "
Will not get rid of her. - Sadye commented on June 14th 19 at 20:32
divide the given array
$a = explode('"', $item);
and get a new array - demario.Durgan commented on June 14th 19 at 20:35
superfluous quotation mark removed of course, just wanted to bring the solution
preg_match_all('/src=\"(.*?)\"/', $content, $array)
to perfection, without much fuss - Sadye commented on June 14th 19 at 20:38

Find more questions by tags PHP