I have a PHP Code that extracts information from a Web Service
<?php
$speechText=$_POST['spokentext'];
echo $speechText.'!';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://nlp.stanford.edu:8080/parser/index.jsp');
curl_setopt($ch, CURLOPT_POST, 3);
curl_setopt($ch,CURLOPT_POSTFIELDS, "query=".$speechText."&parserSelect=English&parse=Parse");
$result = curl_exec($ch);
//echo $result;
curl_close($ch);
$dom = new DOMDocument();
$dom->loadHTML($result);
$xpath = new DOMXPath($dom);
$result = $xpath->query('/html/body/div[2]/div[5]/pre');
echo $result->item(0)->nodeValue;
?>
The variable $result holds the HTML document which is returned. I want to extract some information from it by parsing it. I am using the inbuilt DOM parser, but I am getting this error -
PHP Notice: Trying to get property of non-object
What is the error ?
P.S. - I am a complete n00b in programming :P
Its pretty simple
$dom = new DOMDocument();
@$dom->loadHTML($html);
$xpath = new DOMXpath($dom);
$elements = $xpath->query("/html/body/div[2]/div[6]/pre");
$typed_dependencies_collapsed = array();
if (!is_null($elements)) {
foreach ($elements as $element) {
$nodes = $element->childNodes;
foreach ($nodes as $node) {
echo $node->nodeValue."
";
array_push($typed_dependencies_collapsed,$node->nodeValue);
}
}
}