使用PHP从特定于图像的String中删除IMG标记

I have a block of text that has a particular image that I want to strip out. The problem is that the tag can be with different styles

for e.g

<img src="myimage.png" alt="" class=""/>  

or

<img alt="" class="" src="myimage.png"/>

or

<img class="" alt ="" src="myimage.png"/>

Now how can I remove that particular image tag from my string using PHP?

Something like:

$str = 'Lorem <img alt="" class="" src="myimage.png"/> ipsum <img class="" alt="" src="myimage.png"/> dolor <img src="myimage.png"/> sit...';
echo preg_replace('!<img.*?src="myimage.png".*?/>!i', '', $str);
// output: "Lorem  ipsum  dolor  sit..."

maybe?

if you meant to extract attributes, try

$xpath = new DOMXPath(@DOMDocument::loadHTML($html));
$src = $xpath->evaluate("string(//img/@src)");