I'm approaching web programming. I need to retrieve some informations from a web page. I have the url of the page, so I want the html source code, translate it into xml and then use the dom functions of php to fetch the informations I need.
My php code is this:
$url=$_POST['url']; //url
$doc_html=new DOMDocument();
$doc_html->loadHTML($url); //html page
$doc_xml=new DOMDocument();
$doc_xml->loadXML($doc_html->saveXML()); //xml converted page
$nome_app=new DOMElement($doc_xml->getElementById('title'));
echo $nome_app->nodeValue;
I get this fatal error:
Uncaught exception 'DOMException' with message 'Invalid Character Error' on this line:
$nome_app=new DOMElement($doc_xml->getElementById('title'));
What's wrong? Is it the entire process html-to-xml? I found some example on the web and should work... Thanks!