Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
need help to parse simple XML to PHP
Old 09-22-2011, 06:50 AM need help to parse simple XML to PHP
Average Talker

Posts: 23
Name: paul
Trades: 0
hi,

i'm trying to display this XML rss i receive using PHP , and its not working for me.
can anyone help displaying this?

this is the XML code:
Code:
<RESPONSE>
   <EXPR>CAD</EXPR>
   <EXCH>USD</EXCH>
   <AMOUNT>1</AMOUNT>
   <NPRICES>1</NPRICES>
<CONVERSION>
   <DATE>Thu, 10 May 2001 21:00:00 GMT</DATE>
   <ASK>1.5432</ASK>
   <BID>1.542</BID>
</CONVERSION>
   <EXPR>CAD</EXPR>
   <EXCH>CAD</EXCH>
   <AMOUNT>1</AMOUNT>
   <NPRICES>1</NPRICES>
<CONVERSION>
   <DATE>Fri, 11 May 2001 14:29:54 GMT</DATE>
   <ASK>1.0000</ASK>
   <BID>1.000</BID>
</CONVERSION>
</RESPONSE>


this is the code i wrote, the problem is that the EXPR EXCH... are at the sample level so running a foreach loop is a problem.
Code:
<?php
oandaObj = simplexml_load_file("XMLFILENNAME.xml");
$oandaArr = $oandaObj;
?>
<ul>
<?php foreach ($oandaArr as $key): ?>
<li><?php echo $oandaArr->EXPR;?></li>
<li><?php echo $oandaArr->EXCH;?></li>
<li><?php echo $oandaArr->AMOUNT;?></li>
<li><?php echo $oandaArr->NPRICES;?></li>
<li><?php echo $oandaArr->CONVERSION->DATE;?></li>
<li><?php echo $oandaArr->CONVERSION->BID;?></li>
<li><?php echo $oandaArr->CONVERSION->ASK;?></li>



<?php endforeach;?>
</ul>
datrader is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-22-2011, 08:03 AM Re: need help to parse simple XML to PHP
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Use the $key variable inside the loop, rather than the $oandaArr. As in
PHP Code:
<?php foreach ($oandaArr as $key): ?>
<li><?php echo $key->EXPR?></li>
...
<?php endforeach; ?>
The foreach ($oandaArr as $key) syntax means that the loop will go through all items in $oandaArr, and for each run in the loop $key will represent the current item.
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.

Last edited by lizciz; 09-22-2011 at 08:05 AM..
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Reply     « Reply to need help to parse simple XML to PHP
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.09962 seconds with 12 queries