xml または rss ファイルからデータを解析しようとしています。少し混乱しています。人々はそれが簡単であることを意味すると私に言いますが、私は多くの苦労をしています.
まず、ラジオ番組のニュースをサイトに表示したいと考えています。RSS フィードと API の両方を外部ソースから取得し、xml コンテンツを毎日更新します。ファイルを取得してサーバーに保存するだけで、読み取ることができます。以下はRSSのサンプルです。
<?xml version="1.0"?>
<channel>
<title>external source</title>
<link>http://www.externalsource.com/</link>
<description>external source</description>
<language>en-us</language>
<pubDate>Thu, Jun 3 2011 10:23:56 PDT</pubDate>
<ttl>60</ttl>
<docs>http://blogs.law.harvard.edu/tech/rss</docs>
<item>
<title>08:00 pm</title>
<link>http://www.externalsource.com</link>
</item>
<item>
<title>- Stephen Ace show</title>
<link>http://www.externalsource.com/stephen_ace</link>
<description>Stephens show</description>
</item>
<item>
<title>- Sarah Hardy show</title>
<link>http://www.externalsource.com/sarah_hardy</link>
<description> Sarah's first show in her new slot.</description>
</item>
<item>
<title>- Radio 4 evening show</title>
<link>http://www.externalsource.com/shows/id-453</link>
<description>Bill Grady is supported by co-host Lenny Hillroy</description>
</item>
<item>
<title>- Kiss music evening show will Sady</title>
<link>http://www.externalsource.com/shows/id-112</link>
<description>Sady presents the evening show here at Kiss.</description>
</item>
</channel>
このファイルをtonight.xmlとして保存すると、fread()を使用するPHPスクリプトから24時間夜に更新されます。
その夜に放送されている番組のタイトルだけを表示したいだけです。
MySQL には問題ありませんが、実際にはこれが得られません。私はとても立ち往生しています。
これが私のphpです
<?php
$thexml = simplexml_load_file("tonight.xml");
echo $thexml->getName() . "<br />";
foreach($thexml->children() as $child)
{
echo $child->getName() . ": " . $child . "<br />";
}
テストすると、正しい値が出力されません。