嗨,我需要下面的php脚本来做一个货币转换使用不同的XML文件。
这是一个来自白帽设计http://www.white-hat-web-design.co.uk/articles/php-currency-conversion.php的脚本
需要修改脚本以执行以下操作:
1,php脚本每24小时从rss.timegenie.com/foreign_exchange_rates_forex下载一个xml文件。
rss.timegenie.com/forex.xml或rss.timegenie.com/forex2.xml
然后,它将xml文件数据/内容存储到mysql数据库文件,即货币和汇率。
任何建议都将不胜感激。
发布于 2010-04-08 20:22:07
看看simpleXML load-string or load-file吧。使用它,您可以解析XML内容并提取字符串。例如(摘自PHP手册)
<?php
$string = <<<XML
<?xml version='1.0'?>
<document>
<title>Forty What?</title>
<from>Joe</from>
<to>Jane</to>
<body>
I know that's the answer -- but what's the question?
</body>
</document>
XML;
$xml = simplexml_load_string($string);
var_dump($xml);
?>这将输出:
SimpleXMLElement Object
(
[title] => Forty What?
[from] => Joe
[to] => Jane
[body] =>
I know that's the answer -- but what's the question?
)让我们知道它的进展如何。
发布于 2010-04-08 20:44:05
白帽设计中的脚本使用正则表达式来提取货币和汇率。
正如pinaki提到的,您最好的选择是使用一种更简单、更灵活的解决方案,即加载xml文件并使用simplexml函数解析它。php.net上的示例应该可以让您上手。在下面的xml上练习,当你可以解析它时,你就可以很容易地处理来自timegenie.com的真正的xml:
<data>
<code>AOA</code>
<description>Angola Kwanza</description>
<rate>125.17</rate>
</data>https://stackoverflow.com/questions/2599597
复制相似问题