[英]php xml file load with pegination
我有這個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 limit?
我只是想做個釘子。
問候
嘗試這樣的事情。
$xml = simplexml_load_file($url);
$limit = 0;
$num = 3;
foreach($xml->deal as $deal)
{
if($limit == $num)
break;
....
...
.....
$limit++;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.