I need to put xml into array and then use join function to show xml file
I extract already xml but don’t know how to use join function for this code.
Please help me to figure out this.
Here is xml code:
<ValCurs Date="06.07.2012" name="Ratele oficiale de schimb">
<Valute ID="47">
<NumCode>978</NumCode>
<CharCode>EUR</CharCode>
<Nominal>1</Nominal>
<Name>Euro</Name>
<Value>15.3051</Value>
</Valute>
<Valute ID="44">
<NumCode>840</NumCode>
<CharCode>USD</CharCode>
<Nominal>1</Nominal>
<Name>Dolar S.U.A.</Name>
<Value>12.2343</Value>
Function to extraxt xml :
function curs() {
$date = date("d.m.Y");
$link = 'http://bnm.md/md/official_exchange_rates?get_xml=1&date='.$date;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $link);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$xml_array = curl_exec($ch);
curl_close($ch);
$xml_array = file_get_contents($link);
$values = array();
$curs = new SimpleXMLElement($xml_array);
foreach($curs as $key => $value) {
if (($value->CharCode) == 'USD') {
$values .= $value->Name." - ".$value->Value.", ";
}
if (($value->CharCode) == 'EUR') {
$values .= $value->Name." - ".$value->Value.", ";
}
}
$value = str_replace(',', '.', $values);
return $value;
}
It is not overly clear what you are asking for, but if I gather it correctly you want to do something like this. Note you were mixing array and string logic for the variable $values.
Note: I’m not sure on the usefulness of merging these strings with “.” i’d expect you’d be after something like \n.