Page 1 of 1

Display number of items in xml file

Posted: Mon Jul 31, 2006 1:43 pm
by Tomcat7194
Hello, I'm new to PHP and I have a question.

I'm working with an xml file that shows flight delays (http://www.flightstats.com/go/rss/airportdelays.do).
In PHP, I need to make a variable that displays the total number of items in the flight delay xml file (i.e. the total number of current delays). I don't need to parse any of the information within the items--I just need code that will look at the XML file and make a variable that shows how many there are.

So for example, if there were two items in the XML file, the variable would equal 2, and I could display something like "Total Reported Delays=2".

Is there any simple way to do this? Will I need some kind of external file to parse the XML, or can PHP handle this kind of thing itself?

Thanks in advance,
Tom

Posted: Mon Jul 31, 2006 1:46 pm
by Nathaniel
Just grab the xml file as a string, and use substr_count to count the instances of whatever tag you are using to hold a delay.

Posted: Tue Aug 01, 2006 10:55 am
by Tomcat7194
What should I use to load the XML as a string? My code right now keeps simply loading the XML url rather than the actual XML.

Thanks

Posted: Tue Aug 01, 2006 11:05 am
by feyd
file_get_contents() perhaps.

Posted: Tue Aug 01, 2006 11:07 am
by Oren

Posted: Tue Aug 01, 2006 11:25 am
by Tomcat7194
My host is only running version 4.4, so no simple xml, but the file_get_contents worked perfectly. Thanks for the tip.
Tom