Solved

PHP Sorting Results XML

Posted on 2007-12-06
6
2,422 Views
Last Modified: 2012-05-05
Hello, Can anyone let me know what is the best way to parse and sort results in an XML feed through PHP. Thanks.
0
Comment
Question by:vfetty
  • 3
  • 3
6 Comments
 
LVL 5

Expert Comment

by:nacker2000
ID: 20421504
Hi,

Have a look at SimpleXML: http://uk3.php.net/simplexml
0
 

Author Comment

by:vfetty
ID: 20422036
Thanks, I have seen that before but not sure what half that stuff is and how do you sort results with it?
0
 
LVL 5

Expert Comment

by:nacker2000
ID: 20422160
Well it's easy to use if you are loading in an XML structure:

$data = '<movie>
                 <title>value</title>
              </movie>';

/* parse as xml */
$xml_data = simplexml_load_string($data);

And then to read out a value you do:

/* get data */
$value = $xml_data->movie->title;

The link I posted above shows some basic examples and there are lots of other sites that explain how to use it. Once you have read a few examples it will become easy to use.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:vfetty
ID: 20422222
I do not see a sort function there, please keep in mind I'm new to this and I do not need a full blown example but a sorting example would be nice.  Plus I am dealing with raw XML not RSS. Thanks for you help.
0
 
LVL 5

Accepted Solution

by:
nacker2000 earned 125 total points
ID: 20422277
The SimpleXML will work with raw XML, provided it is formatted correctly. What will the sort function be used for?

The reason I ask is that once you have the XML parsed you use PHP to do your sorting if its just for something simple like outputing certain values.
0
 

Author Comment

by:vfetty
ID: 20422317
The sort function will be like page 1, 2, 3, 4, 5, 6 by alpha so because the results are way to much to put on one return (about 120 results from the XML file) wanted to break them up into 10 per page.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now