Set an empty attribute on DomNode / DomDocument
If you set an attribute on a domnode
with $theNode->setAttribute($name,"")
, it requires a value be passed along with it & it will print as theattribute=""
. It requires a small workaround to have it print theattribute
without the =""
.
You just have to create a DOMAttr
without setting a value for it, and add the attribute
$theDomNode->setAttributeNode(new \DOMAttr($ph));
I needed this for RBDoc, a DOMDocument improvement. It has a compiler that replaces php code with a random string before initializing DOMDocument, then will print back out the actual php code later. The =""
was then causing problems, so I had to figure this one out.