我有一个包含500多个项目的长xml数据文件,它有以下形式:
<?xml version="1.0" encoding="ISO-8859-1"?>
<CATALOG>
<ITEM>
<TITLE>ITEM name</TITLE>
<TYPE>TYPE </TYPE>
<DESCIPTION>DESCIPTIONiliate Page CPM</DESCIPTION>
<PRICE>PRICE</PRICE>
<ITEM>http://mysite.com/item-link</ITEM>
</ITEM>
</CATALOG>
Run Code Online (Sandbox Code Playgroud)
我在php页面中使用以下代码从xml文件导入数据:
<?php
$ITEMSS = new SimpleXMLElement('ITEMS.xml', null, true);
echo <<<EOF
<table width="100%" align="center" border="1" bordercolor="#0099ff" cellpadding="1" cellspacing="0">
<tr>
<th bgcolor="#66ccff"><span class="style4">ITEM Name</span></th>
<th bgcolor="#66ccff"><span class="style4">item TYPE </span></th>
<th bgcolor="#66ccff"><span class="style4">item DESCIPTION </span></th>
<th bgcolor="#66ccff"><span class="style4">item PRICE</span></th>
<th bgcolor="#66ccff"><span class="style4">link to item</span></th>
</tr>
EOF;
foreach($ITEMSS as $ITEMS) // loop through our DATAS
{
echo <<<EOF
<tr height="30" align=middle>
<td><a href="{$ITEMS->ITEM}" target="_blank"><span class="STYLE7">{$ITEMS->TITLE}</span></a></td>
<td><span class="STYLE8">{$ITEMS->TYPE}</span></td> …Run Code Online (Sandbox Code Playgroud)