重要なお知らせ

「教えて! goo」は2025年9月17日(水)をもちまして、サービスを終了いたします。詳細はこちら>

電子書籍の厳選無料作品が豊富!

こんにちは、rss取得方法を勉強中なのですが
下記phpでrssを取得しているのですが、$xml->entry[$i]['item']->titleなどで
うまく表示されません。(外部phpからxoopsのpicoというモジュールのrssを取得しようとしています。)

phpコード
$rssurl = "url";
$xml = simplexml_load_file($rssurl);
$num_of_data = 4;
$outdata = "";
for ($i=0; $i<$num_of_data; $i++){
$outdata .= "<li>";
$outdata .= "<a href=\"";
$outdata .= $xml->entry[$i]->link[href];
$outdata .= "\">";
$outdata .= $xml->entry[$i]['item']->title;
$outdata .= "</a><br />\n";
$outdata .= "</li>";
}


xmlの中身
SimpleXMLElement Object ( [@attributes] => Array ( [version] => 2.0 ) [channel] => SimpleXMLElement Object ( [title] => XOOPS Cube Site - pico [link] => http://localhost/xoops/modules/pico/ [description] => SimpleXMLElement Object ( ) [lastBuildDate] => Thu, 13 Dec 2012 02:52:29 +0100 [docs] => http://backend.userland.com/rss/ [generator] => XOOPS - pico [category] => TOP [webMaster] => admin@hotmail.co.jp [language] => ja [item] => Array ( [0] => SimpleXMLElement Object ( [title] => コンテンツ1 [link] => http://localhost/xoops/modules/pico/index.php/in … [description] => 正式名称:NARUTO -ナルト概要:体内に九尾の妖狐を封印された落ちこぼれ忍者・うずまきナルトが、里一番の忍である火影を目指し、数々の試練を乗り越え成長していく物語。仲間との友... [guid] => http://localhost/xoops/modules/pico/index.php/in … [pubDate] => Thu, 13 Dec 2012 02:52:29 +0100 [category] => アニメタイトル ) [1] => SimpleXMLElement Object ( [title] => ee [link] => http://localhost/xoops/modules/pico/index.php/co … [description] => e [guid] => http://localhost/xoops/modules/pico/index.php/co … [pubDate] => Thu, 13 Dec 2012 02:03:51 +0100 [category] => アニメタイトル ) [2] => SimpleXMLElement Object ( [title] => コンテンツ6 [link] => http://localhost/xoops/modules/pico/index.php/co … [description] => コンテンツ2 [guid] => http://localhost/xoops/modules/pico/index.php/co … [pubDate] => Thu, 13 Dec 2012 01:53:17 +0100 [category] => アニメタイトル ) ) ) )

A 回答 (1件)

せめて「ソース表示」にした状態を転記してください。

構造が読み取れません。

[item] => Array ( [0] => SimpleXMLElement Object ( [title] => コンテンツ1

となっていますから、最低でも

$xml->channel->item[$i]->title

などとなるのではないですかね。



var_dumpで$xml->channel、$xml->channel->item、$xml->channel->item[0]などと少しずつ辿ってみた方が早いです。
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!