How to find src attribute of image tag in php?

In my case, I had a string containing exactly one <img /> tag (and no other markup). And I was trying to get the src attribute. // get the featured image $image = '<img src="path/to/image_file" />'; // get the src for that image $pattern = '/src="([^"]*)"/'; preg_match($pattern, $image, $matches); $src = $matches[1]; unset($matches); In the … Continue reading How to find src attribute of image tag in php?