读取XML文件并将数据存储到mysql数据库 [英] Reading an XML file and store data to mysql database

查看:305
本文介绍了读取XML文件并将数据存储到mysql数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要以下php脚本使用不同的XML文件进行货币转换。

Hi I need the following php script to do a currency conversion using a different XML file.

它是白帽子设计的脚本
http://www.white-hat-web- design.co.uk/articles/php-currency-conversion.php

Its a script from white-hat design http://www.white-hat-web-design.co.uk/articles/php-currency-conversion.php

该脚本需要进行以下修改:

The script needs to be amended to do the following:

1,PHP脚本每24小时从
rss.timegenie.com/foreign_exchange_rates_forex

1, The php script downloads every 24 hours an xml file from rss.timegenie.com/foreign_exchange_rates_forex

rss下载xml文件.timegenie.com / forex.xml或rss.timegenie.com/forex2.xml

rss.timegenie.com/forex.xml or rss.timegenie.com/forex2.xml

2,然后将xml文件的数据/内容存储到mysql数据库文件,即货币和汇率。

2, It then stores the xml file data/contents to a mysql database file ie currency and rate.

任何建议都将不胜感激。

Any advice would be appreciated.

推荐答案

白帽子设计中的脚本使用正则表达式提取货币和汇率。

The script from white hat design uses a regular expression to extract the currency and rate.

如pinaki所述,您最好的选择是使用更简单,更灵活的解决方案来加载xml文件并使用simplexml函数进行解析。 php.net上的示例应该可以帮助您。在以下xml上进行练习,当您可以解析它时,您将可以轻松地从timegenie.com处理真正的xml:

As pinaki mentioned your best bet is to use a more simpler and flexible solution of loading the xml file and parsing it with the simplexml functions. The examples on php.net should get you going. Practice on the following xml and when you can parse this then you you'll easily be able to tackle the real xml from timegenie.com :

<data>
<code>AOA</code>
<description>Angola Kwanza</description>
<rate>125.17</rate>
</data>

这篇关于读取XML文件并将数据存储到mysql数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆