You could also do this by opening an html file using file_get_contents('file.html');
and writing to file with file_put_contents('file.html');
I used the following example, with a custom function
//get HTML File
$html_File_With_Images = file_get_contents('file.html_html');
//strip images
$html_file_without_Images = stripImages($html_file_with_images);
//save html file
fopen('file.html', 'W');//open file with write permission
file_put_contents('file.html', $html_file_without_Images);//this writes the contents to file
fclose('file.html');//always close files that you have opened to prevent memory leaks
function stripImages($string)//Recursiveley removes images from an html string
{
$imageStart = strpos($string, "<img");//find "<img" in the html string
$imageSubString = substr($string,$imageStart);//you need to isolate the end of the image, because images do not have end tags
$imageLength = strpos($imageSubString, ">");//find the image end tag, which will be the first > charachter from the start of the tag
$imageEnd = $imageStart + $imageLength + 1;//this integer points to where the image ends (+1 because of 0-indexing)
$returnStart = substr($string,0,$imageStart);//this is the retun string, before the image
$returnEnd = substr($string,$imageEnd);//this is the return string, after the image
$return = $returnStart . $returnEnd;//this appends the $returnStart and $returnEnd strings into one string
$test = strpos($return, "<img");//tests if there are more images in the string
if($test !== false)//must use !== because strpos can return 0 (which looks false) if the searched string is at the start of the string
{
$return = stripImages($return);//this recursiveley runs the function until there are no more images to display
}
return($return);//output
}