Return closest 5 results to a search value from an XML

I have an XML which is supplied by a third party and I have no control over its formatting. It looks like this:

[code]


<quote_detail rate=“3.375” price="-0.440">
value
</quote_detail>




<quote_detail rate=“3.548” price="-0.230">
value
</quote_detail>




<quote_detail rate=“3.799” price=“1.120”>
value
</quote_detail>

[/code]

What I need to do is return the result (vendor_name, rate and price) that has a price closest to zero without going over as well as the next two above and below. The ideal result would look something like this (where the middle one is closest to zero):

  1. Company Z / 3.875 / -1.375
  2. Company Y / 3.750 / -0.875
  3. Company X / 3.375 / -0.440
  4. Company A / 3.500 / 0.250
  5. Company B / 3.375 / 1.125

I’m not sure about the logic required to do this or how to preserve the XML information while running said logic. Any help?

You can start by looking at the iTunes Meta Data Page on this forum he did exactly what your talking about other wise here is a great place to start.

simplexml

http://php.net/manual/en/book.simplexml.php

Yes, as Andrew said, php.net/manual is the go-to for most all code information.

I also use w3schools for tutorials on just about everything in the programming world.

You just need to search correctly for what you need.

Here is their tutorial on this subject: http://www.w3schools.com/php/php_xml_simplexml.asp

Might give you further info… Good luck…

Sponsor our Newsletter | Privacy Policy | Terms of Service