摘要:下面小编就为大家带来一篇php操作xml并将其插入数据库的实现方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧。如下所示:<?php header('content-type:text/html;charset=utf-8'); mysql_connect('localhost', 'root',&n
下面小编就为大家带来一篇php操作xml并将其插入数据库的实现方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧。
如下所示:
<?php
header('content-type:text/html;charset=utf-8');
mysql_connect('localhost', 'root', '');
mysql_SELECT_db('test');
mysql_query('SET names utf8');
$xml_array=simplexml_load_file('suggest.xml'); //将XML中的数据,读取到数组对象中
foreach($xml_array as $tmp){
$sql = "INSERT into `countries` (`id` ,`value`) VALUES (NULL , '".$tmp->field."')";
mysql_query($sql);
echo $tmp->field."<br>";
}
?>更多关于php操作xml并将其插入数据库的实现方法请关注PHP中文网(www.php.cn)其它文章!