Function extract image from HTML content using PHP via regex
If you would like to only extract out image from your HTML contents. You may use the function below to do so.
What the codes does is, it will scan through your HTML contents and look for image patterns, and return all of your images in array format.
#—————————————————————————————————-
# Function to get clean image
#—————————————————————————————————-
function getcleanimage($data){
$pattern = “/src=[\"']?([^\"']?.*(png|jpg|gif|jpeg))[\"']?/i”;
preg_match_all($pattern, $data, $images);
return $images;
}
#—————————————————————————————————-
