如何获得回显的文本文件的内容?

How to get content of a text file echoed?

我正在尝试构建一个 rss reader,它从 .txt 文件中获取 URL。我怎样才能将它输入 $rss->load(Here, I would like to echo a URL written in a text file); 以便它从 .txt 文件中读取 url?

我在 PHP 方面绝对不先进,但我在这里也没有找到任何答案。感谢您的帮助!

 <?php
    $rss = new DOMDocument();
    $rss->load('here I would like to echo a URL written in a text file');

    $feed = array();
    foreach ($rss->getElementsByTagName('item') as $node) {
        $item = array ( 
            'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
            'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
            'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
            'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
            );
        array_push($feed, $item);
    }
    $limit = 5;
    for($x=0;$x<$limit;$x++) {
        $title = str_replace(' & ', ' &amp; ', $feed[$x]['title']);
        $link = $feed[$x]['link'];
        $description = $feed[$x]['desc'];
        $date = date('d-m-y H:i &#187; ', strtotime($feed[$x]['date']));
        echo ''.$date.'';
        echo '<b><a href="'.$link.'" title="'.$title.'">'.$title.'</a></b>. ';

        echo ''.$description.'';
        echo '<hr>';
    }
?>

就一个URL,没有装饰?使用 file_get_contents() 读取文件,然后使用 trim() 删除任何不需要的行结尾(如果有):

$url = trim(file_get_contents('/path/to/file'));
$rss->load($url);

或者只是:

$rss->load(trim(file_get_contents('/path/to/file')));