I’m trying to get some data from a HTML
$xdata = simplexml_import_dom($doc);
$datas = $xdata->xpath("//*[@class='proglist']");
$aData = array();
foreach($datas as $data)
{
$rightdatas = $data->xpath("*[@class='progright']");
$rt = $rightdatas[0];
print_r($rt);
$content = $rt->xpath("*[@class='progrighthead']");
print_r($content );
}
If I’m printing out the content of the $rt than the progrighthead class is there, but the $content variable is empty. Why?
Why do I receiving the same result for the following syntax?
$xdata = simplexml_import_dom($doc);
$datas = $xdata->xpath("//*[@class='proglist']");
$aData = array();
foreach($datas as $data)
{
$rightdatas = $data->xpath("*[@class='progright']");
$rt = $rightdatas[0];
print_r($rt);
$content = $rt->xpath("*[@class='progrighthead']");
}
and
$datas = $xdata->xpath("//*[@class='progrighthead']");
progrighthead is not a child of progright, but a descendant. Use
Putting
//at the beginning means searching from the root, not from the current element.