测试.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<propertyList>
<business type="food">
<listingAgent id="1">
<name>Spiro Abelas</name>
<email>spiro@abelas.com.au</email>
</listingAgent>
</business>
<business type="food">
<listingAgent id="2">
<name>andy</name>
<email>andy@abelas.com.au</email>
</listingAgent>
</business>
</propertyList>
PHP 代码将 XML 文件解释为对象
<?php
if (file_exists('test.xml')) {
$xml = simplexml_load_file('test.xml');
echo "<pre>";
print_r($xml);
echo "</pre>";
} else {
exit('Failed to open test.xml.');
}
?>
输出
SimpleXMLElement Object
(
[business] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[type] => food
)
[listingAgent] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 1
)
[name] => spiro
[email] => spiro@abelas.com.au
)
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[type] => food
)
[listingAgent] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 2
)
[name] => andy
[email] => andy@abelas.com.au
)
)))
表结构
我想将这样的数据插入表格
但我不知道如何从数组中检索数据并插入多行
所以请指导我如何解决它