Maison > développement back-end > tutoriel php > 新人提问:这个有关问题也太诡异了吧。关于RSS的基础应用

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Libérer: 2016-06-13 13:20:24
original
943 Les gens l'ont consulté

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

PHP code

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

<!--

 

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><a href="%5C%22%24link%5C%22">' . $title . '</a><br>' . $description . '</p>';

    }

?>

Copier après la connexion


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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

<!--

 

Code highlighting produced by Actipro CodeHighlighter (freeware)

http://www.CodeHighlighter.com/

 

-->

  <?xml version="1.0" encoding="UTF-8" ?>

- <rss version="2.0">

- <channel>

  <title>XHTML</title>

  <link>http://localhost/PHPProject/NewFile.html

  <description>Free web building tutorials</description>

  <category>Web development</category>

  <language>en-US</language>

  <copyright>2006 w3school.com.cn. All rights reserved.</copyright>

- <item>

  <title>RSS Tutorial</title>

  <link>http://localhost/PHPProject/NewFile.html

  <description>New RSS tutorial on W3School</description>

  <author>service@w3school.com.cn</author>

  <comments>http://localhost/PHPProject/NewFile.html</comments>

  </item>

  </channel>

  </rss>

Copier après la connexion


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

1

2

3

4

5

6

7

<channel>

     ...

     <item>...</item>

     <item>...</item>

     <!-- 可能有多个 -->

</channel>

<br><font color="#e78608">------解决方案--------------------</font><br>

Copier après la connexion
探讨

引用:

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

$title
$description

";


这个不行吗??

echo '

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

';

不是说……
Étiquettes associées:
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal