1

我有这个 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 限制?

我只想做一个钉子。

问候

4

1 回答 1

0

尝试这样的事情。

$xml = simplexml_load_file($url);
$limit = 0;
$num = 3;
foreach($xml->deal as $deal)
{
if($limit == $num)
break;
....
...
.....
$limit++;
}
于 2013-02-23T23:17:53.567 回答