prakash Posted December 13, 2007 Share Posted December 13, 2007 how can I convert simple xml data like below to html table using php <?xml version="1.0" encoding="UTF-8"?> <result> <pagerank>8</pagerank> <alexaRank>5</alexaRank> <dmoz>1</dmoz> <backlinksGoogle>825,000</backlinksGoogle> <backlinksYahoo>2,300,000</backlinksYahoo> <backlinksMSN>0</backlinksMSN> <resultsAltaVista>47,100,000</resultsAltaVista> <resultsAllTheWeb>39,500,000</resultsAllTheWeb> <thumbnail>http://images.websnapr.com/?url=msn.com&size=t</thumbnail> </result> Quote Link to comment Share on other sites More sharing options...
marcus Posted December 13, 2007 Share Posted December 13, 2007 You can use some regex to complete this task. Quote Link to comment Share on other sites More sharing options...
lur Posted December 13, 2007 Share Posted December 13, 2007 if (phpversion() >= 5) { echo '<table>', PHP_EOL; foreach (simplexml_load_string($xml) as $key => $value) { echo '<tr><td>', $key, '</td><td>', $value, '</td></tr>', PHP_EOL; } echo '</table>', PHP_EOL; } Quote Link to comment Share on other sites More sharing options...
prakash Posted December 13, 2007 Author Share Posted December 13, 2007 if (phpversion() >= 5) { echo '<table>', PHP_EOL; foreach (simplexml_load_string($xml) as $key => $value) { echo '<tr><td>', $key, '</td><td>', $value, '</td></tr>', PHP_EOL; } echo '</table>', PHP_EOL; } actually the xml is built from a php script on another file like somexmlfile.php by passing a varaible let's say somexmlfile.php?url=msn.com so how can I set the value of $xml to the somexmlfile.php?url=msn.com output Quote Link to comment Share on other sites More sharing options...
lur Posted December 13, 2007 Share Posted December 13, 2007 $xml = file_get_contents('http://example.net/somexmlfile.php?url=msn.com'); Quote Link to comment Share on other sites More sharing options...
prakash Posted December 13, 2007 Author Share Posted December 13, 2007 $xml = file_get_contents('http://example.net/somexmlfile.php?url=msn.com'); thanks a lot it's really helped for my script Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.