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> Link to comment https://forums.phpfreaks.com/topic/81492-solved-convertine-simple-xml-doc-to-html-table-with-php/ 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. Link to comment https://forums.phpfreaks.com/topic/81492-solved-convertine-simple-xml-doc-to-html-table-with-php/#findComment-413737 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; } Link to comment https://forums.phpfreaks.com/topic/81492-solved-convertine-simple-xml-doc-to-html-table-with-php/#findComment-413739 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 Link to comment https://forums.phpfreaks.com/topic/81492-solved-convertine-simple-xml-doc-to-html-table-with-php/#findComment-413770 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'); Link to comment https://forums.phpfreaks.com/topic/81492-solved-convertine-simple-xml-doc-to-html-table-with-php/#findComment-413786 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 Link to comment https://forums.phpfreaks.com/topic/81492-solved-convertine-simple-xml-doc-to-html-table-with-php/#findComment-413800 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.