I want to pull phone number from a website, but in the end I got error.
Error: Notice: Trying to get property of non-object in C:\xampp\htdocs\testing.php on line 15
my code is as below:
$ch=curl_init("http://www.mudah.my/LG+G+Pro+2+D838+16GB+5+9in+2+26GHz+3GB+RAM+NEW+SET-30256077.htm");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$cl = curl_exec($ch);
$dom = new DOMDocument();
@$dom->loadHTML($cl);
$xpath = new DOMXpath($dom);
$phoneNo = $xpath->query("//div[@class='contact-phoneno']/text()");
$phone = $phoneNo->item(0)->nodeValue;
echo $phone;
With:
$phoneNo = $xpath->query("//div[@class='contact-phoneno']");
$phone = $phoneNo->item(0)->textContent;
I obtain: 013611xxxx