I am working on my PHP to search for the images that come the specific address so I want to remove all of these img tags.
I have the img tags which show like this:
<img src="http://example.com/someimage1.jpeg">
<img src="http://example.com/someimage2.jpeg">
<img src="http://example.com/someimage3.jpeg">
<img src="http://example.com/someimage4.jpeg">
<img style="OVERFLOW: hidden; WIDTH: 0px; MAX-HEIGHT: 0px" alt="" src="http://test.mydomain.com/project433q325/track/Images/signature.gif?id=446&etc=1586624376">
When I try this:
foreach ($src as $image) {
$image = preg_replace("\<img src\=\"(.+)\"(.+)\/\>/i", '', $src);
}
It will not remove the img tag, so I have also tried this:
foreach ($src as $image) {
$image = preg_replace("/<img[^>]+\>/i", "", $src);
}
I still have the same issue as it will not remove the img tag.
Here is the full code:
if (strpos($inbox_message, 'http://test.mydomain.com/project433q325/track/Images/signature.gif?') !== false) {
$doc = new DOMDocument();
$doc->loadHTML($inbox_message);
$xpath = new DOMXpath($doc);
$src = $xpath->evaluate("string(//img/@src)");
if ($src) {
foreach ($src as $image) {
//image->nodeValue = preg_replace('<img.*?src='.$src.'.*?/>!i', '', $src);
//$src = preg_replace("/<img[^>]+\>/i", "", $src);
$image = preg_replace("\<img src\=\"(.+)\"(.+)\/\>/i", '', $src);
//}
}
$inbox_message = $doc->saveHTML();
}
What I am trying to do is I only want to search for the img tags that have the src address which show 'http://test.mydomain.com/project433q325/track/Images/signature.gif?' and remove them.
Can you please show me an example how I can search for each img tag that have specific src address so I can remove each img tags using preg_replace?
Thank you.
EDIT: Here is the $inbox_message variable:
$inbox_message = '<img src="http://example.com/someimage1.jpeg"><img src="http://example.com/someimage2.jpeg"><img src="http://example.com/someimage3.jpeg"><img src="http://example.com/someimage4.jpeg"><img style="OVERFLOW: hidden; WIDTH: 0px; MAX-HEIGHT: 0px" alt="" src="http://test.mydomain.com/project433q325/track/Images/signature.gif?id=446&etc=1586624376">';