I have a method that looks like this:
function braces(DOMElement $node){
$path = $node->getNodePath();
$xpath = new DOMXPath($node->ownerDocument);
$nodes = $xpath->query($path . '[*=(contains(., "{{") and contains(., "}}"))]');
var_dump($nodes);
}
I have created the following two test cases:
Test Case 1
$dom = new DOMDocument();
$dom->loadHTML('<div data-id="{{cat}}">
<a href="http://google.com">Google</a>
</div>',LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED);
braces($dom->documentElement);
The var_dump()
on this one does not find the attribute with {{
and }}
.
Here is test case 1's resulting output:
object(DOMNodeList)#4 (1) {
["length"]=>
int(0)
}
Test Case 2
$dom = new DOMDocument();
$dom->loadHTML('<div data-id="{{cat}}"></div>',LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED);
braces($dom->documentElement);
When removing the child a
element, the var_dump()
now can find the attribute with {{
and }}
.
Here is test case 2's resulting output:
object(DOMNodeList)#3 (1) {
["length"]=>
int(1)
}
So, my question is why can't it find the value when the item has children?