I load html using DOMDocument
and then apply DOMXPath
filters on it. Does any of these objects have a way to distinguish attribute with empty string value and attribute without a value?
<input required="">
<input required>
I know in both cases the required attribute is technically true, but when I call DOMDocument::saveHTML()
, I can see the them as shown. Now I want to filter only those with empty string value. The closest solution I found was
$xpath = new DOMXPath($dom);
$xpath->query("//*[@*[string-length()=0]]");
But unfortunately this also matches the attributes without value.