I really did not think to make a post about it, but as far as I have lost about 15 minutes in research how to do it, it is obviously that spending some 10 minutes more would be valuable.
The idea is to have a php file with a web link and to produce a simple list from it in PHP. Something trivial, if you do not forget the rule for the xml lists – they should all be with one root, otherwise there is an error.
So here are the two files the test.php and the example.xml, that provide the abovementioned result. Enjoy them:
1 2 3 4 5 6 7 8 9 10 11 12 |
<?php $xml=simplexml_load_file("example.xml"); echo "<ul>\n"; foreach($xml->user as $unit) { $my_name = htmlspecialchars((string)$unit->name); $my_href = htmlspecialchars((string)$unit->website); echo "<li><a href=\"$my_href\">$my_name</a></li>\n"; } echo "</ul>\n"; ?> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<?xml version="1.0"?> <users> <user> <name>Vitosh</name> <website>https://www.vitoshacademy.com</website> </user> <user> <name>Hater</name> <website>http://www.hategame.com</website> </user> <user> <name>Business Vitosh</name> <website>http://www.vit-consulting.com</website> </user> </users> |
Available also in GitHub! 🙂