php - How to select two different elements with an XPath query -
php - How to select two different elements with an XPath query -
i select <a id="categorybrandicon">
with:
$item = $xpath->query("//a[@id='categorybrandicon']")->item(0);
how modify code select <a id="categorybrandicon">
, <input type="hidden">
tags?
selecting inputs if input[@type='hidden']
don't know how chain two.
with css selectors a#categorybrandicon, input[type="hidden"]
yes combine them in single xpath query thru pipe. example:
$sample_markup = ' <div class="container"> <a id="categorybrandicon" href="#">test</a> <input type="hidden" /> <input type="text" /> <h1>test</h1> </div> '; $dom = new domdocument(); $dom->loadhtml($sample_markup); $xpath = new domxpath($dom); $elements = $xpath->query("//a[@id='categorybrandicon'] | //input[@type='hidden']"); foreach($elements $e) { // loop thru found elements }
php xpath css-selectors
Comments
Post a Comment