简体   繁体   English

如何使用SimpleXML将rss提要项保存为PHP中的单个页面

[英]How to save rss feed item as single page in PHP using SimpleXML

how to save rss feeds item as a subpage or any were in the domain using php. 如何使用php将RSS供稿项目保存为子页面或域中的任何子页面。 each item must be saved as a single page (html or php). 每个项目必须保存为单个页面(html或php)。

below given is the php code how i pulled the xml using simpleXML. 下面给出的是php代码,我如何使用simpleXML提取xml。 i want to know a way to save this results as of each content (items) as a page (html or php). 我想知道一种将结果保存为页面(html或php)的方法。

    <?php

function getFeed($feed_url) {

    $content = file_get_contents($feed_url);

    $x = new SimpleXmlElement($content);
    echo "<ul>";

    foreach($x->channel->item as $entry) {
        echo "
        <li>
          <a href='$entry->link' title='$entry->title'>" . $entry->title . "</a>
          <p href='$entry->link' title='$entry->title'>" . $entry->{'author'} . "</p>
          <a href='$entry->link' title='$entry->title'>" . $entry->enclosure . "</a>

          ";

    echo "  </li>";
        }

    echo "</ul>";

Try this: 尝试这个:

function getFeed($feed_url) {
    $content = file_get_contents($feed_url);
    $x = new SimpleXmlElement($content);
    $html = '<ul>';

    foreach($x->channel->item as $entry) {
        $html .= "<li>
            <a href='$entry->link' title='$entry->title'>" . $entry->title . "</a>
            <p href='$entry->link' title='$entry->title'>" . $entry->{'author'} . "</p>
            <a href='$entry->link' title='$entry->title'>" . $entry->enclosure . "</a>
            </li>";
    }
    $html .= '</ul>';

    // The name of the file
    $fileName = 'file.html';
    // Create the file
    $fileHandler = fopen($fileName, 'w+');
    // Send the $html variable to be written in the opened file
    fwrite($fileHandler, $html);
    // Close file
    fclose($fileHandler);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM