I have a html string that contains many images.each image has some attribute like class ,id , style , ....
I want remove all attribute from img except src and alt.
before :
<img title="How to" alt="How to" src="windows_en.jpg" loading="lazy" width="1280" height="720" class="img-first">
I want this output:
<img alt="How to" src="windows_en.jpg">
I want Remove all Attribute from img except src and alt. I try this :
$desc = preg_replace("/(<img\\s)[^>]*((src|alt)=\\S+)[^>]*/i", "$1$2$3", $desc);
but not work fine. please help.