<?php
class imageChecker
{
private $missingImg = array();
private function initArray()
{
array_push($this->missingImg, "/mh_images/new_titlebar_template.dwt_r2_c5.gif");
array_push($this->missingImg, "/mh_images/spacer.gif");
}
private function imgChecker($item)
{
preg_match("#src=\"(.*?)\"#si", $item[0], $match);
return in_array($match[1], $this->missingImg) ? "" : $item[0];
}
function __construct($srcFileName, $destFileName)
{
$this->initArray();
$content = file_get_contents(__DIR__."/".$srcFileName);
$result = preg_replace_callback("#<img(.*?)>#si", array($this, "imgChecker"), $content);
file_put_contents(__DIR__."/".$destFileName, $result);
}
}
$imageChecker = new imageChecker("filename.txt", "result.txt");
?>
function imgChecker($item)
{
$missingImg =
[
"/mh_images/new_titlebar_template.dwt_r2_c5.gif",
"/mh_images/spacer.gif"
];
preg_match("#src=\"(.*?)\"#si", $item[0], $match);
// return file_exists($match[1]) ? item : "";
return in_array($match[1], $missingImg) ? "" : $item[0];
}
$content = file_get_contents(__DIR__."/filename.txt");
$result = preg_replace_callback("#<img(.*?)>#si", "imgChecker", $content);
file_put_contents(__DIR__."/result.txt", $result);