How parsing xml from url and get attribute php -


i need parsing xml file parsing, can parsing local file, how can parsing file url?

i use php code

<?php include '/example1.php'; $string = $xmlstr;  $xml = simplexml_load_string($string); foreach($xml->row->exchangerate[0]->attributes() $a => $b) {     echo $a,'="',$b,"\"\n"; }  ?> 

example1.php code

<?php $xmlstr = <<<xml <exchangerates>     <row>         <exchangerate ccy="rur" base_ccy="uah" buy="0.33291" sale="0.33291"/>     </row>      <row>         <exchangerate ccy="eur" base_ccy="uah" buy="18.60253" sale="18.60253"/>     </row>      <row>         <exchangerate ccy="usd" base_ccy="uah" buy="14.97306" sale="14.97306"/>     </row> </exchangerates> xml; ?> 

just feed necessary url , use simplexml_load_file() of want use url:

$url = 'https://api.privatbank.ua/p24api/pubinfo?exchange&coursid=3'; $xml = simplexml_load_file($url); foreach($xml->row[0]->exchangerate->attributes() $key => $exchangerate) {     if($key == 'buy' || $key == 'sale') {         $exchangerate = 10 * (float) $exchangerate;     }     echo '<div id="attribute_'.$key.'"></div>','<div id="valuta">'.$exchangerate.'</div><br/>'; } 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -