SimpleXML Xpath结果数组拆分为页面

时间:2012-02-05 15:08:13

标签: php arrays simplexml

有没有一种简单的方法可以将SimpleXML的输出分成页面?假设XML文件有200个元素,但我想在每个页面上将其拆分为20个元素。那就像index.php?page=1

$xml = new SimpleXMLElement(file_get_contents("demofile.xml"));
$per_no = $xml->children();
echo count($per_no) . ' are now active<br />';
$cnt = 0;
foreach ($xml->xpath('/webcams_online/webcam') as $node) {
    if ($cnt == 10) {
        break;
    }
    $itemXML = array(
        'account'         => $node['account'],
        'nickname'        => $node['nickname'],
        'number_visitors' => $node['number_visitors']
    );
    $cnt++;
    ?>
    <?php echo $itemXML['account']; ?>
<?php
}

0 个答案:

没有答案