I am trying to select value from a link but, don't know how to solve this problem.
<li id ="listing" class="listing premium first">
<header>
<h2>
<a href="#">value</a>
</h2>
</header>
</li>
I tried with this code and didn't work.
echo $test = $xpath->evaluate('//li[contains(@class,"listing")]//header//h2//a')->item(0)->nodeValue;
Here's all of my code:
<?php
$getURL = file_get_contents('realestate.com.kh/…');
$dom = new DOMDocument();
@$dom->loadHTML($getURL);
$xpath = new DOMXPath($dom);
/* echo $xpath->evaluate("normalize-space(substring-before(substring-after(//p[contains(text(),'Property ID:')][1], 'Property ID:'), '–'))");*/
echo $test = $xpath->evaluate('//li[contains(@class,"listing")]//header//h2//a')->item(0)->nodeValue;
?>
And here's the actual error I get:
Notice: Trying to get property of non-object in W:\Xampp\htdocs\X\index.php on line 9
Is something wrong with this code? I don't know how to make this work. pls help me anyone. I thanks u all.