我需要将 xml 放入数组中,然后使用 join 函数来显示 xml 文件我已经提取了 xml 但不知道如何使用 join 函数来处理这段代码。请帮我弄清楚这一点。这是xml代码:
<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>
提取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;
}