我有这个xml文件结构:
<?xml version="1.0" encoding="UTF-8"?>
<deals>
<deal>
<deal_id>1</deal_id>
<deal_title> <![CDATA[THE TITLE]]> </deal_title>
<deal_description> <![CDATA[THE DESCRIPTION]]> </deal_description>
<deal_url> <![CDATA[http://www.thedomain.com]]> </deal_url>
<deal_price>12.00</deal_price>
<deal_previous_price>68.00</deal_previous_price>
<deal_discount>82</deal_discount>
<deal_image> <![CDATA[http://www.thedomain.com/images/image.jpg]]> </deal_image>
<deal_shop>DEAL SITE NAME</deal_shop>
</deal>
</deals>
现在我使用下面的代码加载带循环的xml:
<?php
//Path to my xml
$url = "myxml.xml";
// get xml file contents
$xml = simplexml_load_file($url);
foreach($xml->deal as $deal)
{
echo "<p>";
echo "<strong>ID:</strong> ".$deal->deal_id."<br/>";
echo "<strong>Title:</strong> ".$deal->deal_title."<br/>";
echo "<strong>Description:</strong> ".$deal->deal_description."<br/>";
echo "<strong>Url:</strong> ".$deal->deal_url."<br/>";
echo "<strong>Price:</strong> ".$deal->deal_price."<br/>";
echo "<strong>Original Price:</strong> ".$deal->deal_previous_price."<br/>";
echo "<strong>Discount:</strong> ".$deal->deal_discount."<br/>";
echo "<strong>Image:</strong> ".$deal->deal_image."<br/>";
echo "<strong>Deal Shop:</strong> ".$deal->deal_shop."<br/>";
echo "</p>";
}
?>
我得到了所有数据,但我遇到了严重问题..
xml文件有超过400条记录。
是否有可能限制像php限制的加载程序记录?
我只是想加油。
此致
答案 0 :(得分:0)
尝试这样的事情。
$xml = simplexml_load_file($url);
$limit = 0;
$num = 3;
foreach($xml->deal as $deal)
{
if($limit == $num)
break;
....
...
.....
$limit++;
}