Randomly read and display values of an xml file using php
Randomly read and display values of an xml file using php
This script will show you how to read and display the values of an xml file using php. My demo.xml looks like this
<message><name>Antonio Paulo/name><website>http://mistonline.in</website><comment>Good One</comment><date>1305127910</date><user_ip>2.241.68.95</user_ip><user_agent>Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.98 Safari/534.13</user_agent><spam>0</spam></name></message>
Here i am just reading the Name and the Comment TAGS.
< ?php $xml = new SimpleXMLElement('demo.xml', NULL, TRUE); $testi = $xml->children(); if(count($testi) == 0 ) { echo "No Entries Yet"; } else { srand(time()); $random = (rand()%count($testi)); for ($i = 0; $i < count($testi); $i++) { if ($i == $random) { echo "<table><tr><td><img src='img/ico/user-ico-2.png'/></td><td> <b>".$testi[$i]->name . '</b> says <i>' . $testi[$i]->comment . '</i></td></tr>'; } } } ?>Randomly read and display values of an xml file using php,
Incoming search terms:
- get random data from file php (1)
- select data randomly from xml file (1)
- read xml show in table format using php (1)
- read xml file and display in php in a table (1)
- read random xml node php (1)
- pick and read xml file in php script (1)
- javascript read random node from xml file (1)
- how to search data in xml file using javascript in php (1)
- how to get random records from xml using php (1)
- xml random read (1)
Thank you for all.
That’s really help. I was trying to do it alone but don’t work for me.
Thanks Fredderick