I would like to parse the following id: date
How would I select it? I know how to select a class but I have had no luck for an id.
This is what I did with classes:
$xml->xpath('//*[@class="date"]');
I tried switching @class for @id but no luck. What am I doing wrong?
Thank you in advance
@$doc=new DOMDocument();
@$doc->loadHTML($html5);
$xml=simplexml_import_dom($doc);
$images=$xml->xpath('//*[@id="date"]');
$arr= array();
foreach ($images as $img) {
$arr[]= $img;
}
echo $arr[0];
Now that you made me feel bad …
The xpath query below will retrieve all elements that have the attribute id = date. Since you only care about the first one (there shouldn’t be more than one because ID attributes are supposed to be unique … but you never know), you need to reference
item(0)in theDOMNodeListreturned by the xpath query.Hope that helps.