hi, i have a link which shows a xml file https://api.trueknowledge.com/direct_answer?object_metadata=image128,wikipedia,official&question=What's+the+time+in+Chicago%3F&api_account_id=api_songautam&api_password=e1wpseb647fhpaw2 i want to read this xml feed . plz suggest me the best way
you could try simplexml ... http://php.net/manual/en/ref.simplexml.php http://php.net/manual/en/function.simplexml-load-file.php
thanx for ur reply but i have tryed this this is my code : <?php $xmlDoc = new DOMDocument(); $xmlDoc->load('https://api.trueknowledge.com/direct_answer?object_metadata=image128,wikipedia,official &question=What%27s+the+time+in+Chicago%3F&api_account_id=api_songautam&api_password=e1wpseb647fhpaw2'); $x = $xmlDoc->documentElement; foreach ($x->childNodes AS $item) { if($item->nodeName == 'tk:text_result') print $item->nodeValue . "<br />"; } ?> PHP: but this is showing error: Warning: DOMDocument::load() [function.DOMDocument-load]: I/O warning : failed to load external entity "https://api.trueknowledge.com/direct_answer?object_metadata=image128%2Cwikipedia%2Cofficial%20&question=What%2527s%2Bthe%2Btime%2Bin%2BChicago%253F&api_account_id=api_songautam&api_password=e1wpseb647fhpaw2" in C:\xampp\htdocs\test\test.php on line 3 Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\test\test.php on line 6
problem with the url encoding i think ... i tried without the apostrophe in " ... what's ... " eg "whats+the+time" like this:
I've never liked simplexml because I chose to get really good with preg_match_all() ... it handles xml, html & even excel spreadsheets. Likely it's not even installed on your server and that's why you're getting that error. What PHP version are you using? I would code something up and paste it here but I think showing you discussion + code is more beneficial.