Solved

PHP Sorting Results XML

Posted on 2007-12-06
6
2,423 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
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 look for a specific file type in a local or remote server directory using PHP.

912 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

17 Experts available now in Live!

Get 1:1 Help Now