• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

新人提问:这个有关问题也太诡异了吧。关于RSS的基础应用

php 搞代码 3年前 (2022-01-24) 22次浏览 已收录 0个评论

新人提问:这个问题也太诡异了吧。。关于RSS的基础应用

PHP code

<!---ecms Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php    require_once('magpierss/rss_fetch.inc');        $url = "http://localhost/PHPProject/RSS/RSS.xml";    $rss = fetch_rss($url);        $feedTitle = $rss->channel['title'];    echo '<p>Latest News from <strong>' . $feedTitle . '</strong></p>';        foreach ($rss->item as $it) {        $link = $it['link'];        $title = $it['title'];        $description = isset($it['description']) ? $it['description'] : '';                echo '<p>' . $title . '<br />' . $description . '</p>';    }?>

XML:
(http://localhost/PHPProject/RSS/RSS.xml)

XML code

<!---ecms Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->  <?xml version="1.0" encoding="UTF-8" ?> - -   <title>XHTML</title>   <link>http://localhost/PHPProject/NewFile.html   Free web building tutorials   Web<strong>(本文来源gaodai#ma#com搞@@代~&码网</strong><pre>搞代gaodaima码

development en-US 2006 w3school.com.cn. All rights reserved. – RSS Tutorial <link>http://localhost/PHPProject/NewFile.html New RSS tutorial on W3School [email protected] http://localhost/PHPProject/NewFile.html

1.
为什么运行显示为:
Latest News from W3School Home Page

RSS Tutorial
New RSS tutorial on W3School

后点击RSS Tutorial后却显示HTTP 403?

2.
在PHP中的foreach ($rss->item as $it)中的item为什么非要设置items才可以运行成功,否则为
Latest News from W3School Home Page

Notice: Undefined property: MagpieRSS::$item in D:\Apache Group\Apache2\htdocs\PHPProject\index5.php on line 10

Warning: Invalid argument supplied for foreach() in D:\Apache Group\Apache2\htdocs\PHPProject\index5.php on line 10

但我的XML中之内是而非喔。。。。

3.
我修改XML文件之前的中的是“W3School Home Page”,所以运行时显示为Latest News from W3School Home Page;但修改后却如上所示<title>XHTML,为什么刷新后也显示Latest News from W3School Home Page?

就算重启整个zend studio都继续显示Latest News from W3School Home Page,真不明白。。。。也不关缓存的事啊。。我已经清除了缓存了

麻烦各位帮帮忙。。我还有分加的

——解决方案——————–
1. 你的代码有问题:
echo ‘

‘ . $title . ‘
‘ . $description . ‘

‘;
由于 $link在单引号内所以不会被解析。所以链接也就是 本页链接$link
至于为什么403无权限就要看你的服务器设置。

2. RSS标准中规定: A channel may contain any number of s.

XML code

     ...     ...     ...     
------解决方案--------------------

探讨

引用:

你怎么修改的。下面这样呢:
echo "

$title
$description

";

这个不行吗??

echo '

' . $title . '
' . $description . '

';

不是说……


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:新人提问:这个有关问题也太诡异了吧。关于RSS的基础应用

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址