Solved

PHP Sorting Results XML

Posted on 2007-12-06
6
2,425 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Accessing specific element - DOM PHP HTML 8 37
ajax to record click 3 16
JQuery Search Filter 2 40
Reference key in foreach loop 4 22
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

821 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