0
DomDocument를 사용하여 RSS 피드를 가져 오지만 이상한 문제가 발생했습니다. 만약 내가 http://rss.slashdot.org/Slashdot/slashdot 같은 RSS 피드를 잡으면 잘 작동합니다. 그러나 구문 분석하려고하는 RSS 피드는 다음과 같은 문제점을 제공합니다. http://www.ryanhache.com/feedDOMDocument :: getElementsByTagName이 PHP에서 채널을 점유하지 않습니다.
채널 태그를 찾지 못하고 루프를 반복하는 것처럼 보입니다. 상속 한 함수는 다음과 같습니다. 그리고 RSS_Retrieve ($ url)로 호출했습니다. 이러한 함수에서 누락 된 부분은 무엇입니까? 아니면 내가 당기는 피드에 문제가 있습니까?
function RSS_Tags($item, $type)
{
$y = array();
$tnl = $item->getElementsByTagName("title");
$tnl = $tnl->item(0);
$title = $tnl->firstChild->textContent;
$tnl = $item->getElementsByTagName("link");
$tnl = $tnl->item(0);
$link = $tnl->firstChild->textContent;
$tnl = $item->getElementsByTagName("pubDate");
$tnl = $tnl->item(0);
$date = $tnl->firstChild->textContent;
$tnl = $item->getElementsByTagName("description");
$tnl = $tnl->item(0);
$description = $tnl->firstChild->textContent;
$y["title"] = $title;
$y["link"] = $link;
$y["date"] = $date;
$y["description"] = $description;
$y["type"] = $type;
return $y;
}
function RSS_Channel($channel)
{
global $RSS_Content;
$items = $channel->getElementsByTagName("item");
// Processing channel
$y = RSS_Tags($channel, 0); // get description of channel, type 0
array_push($RSS_Content, $y);
// Processing articles
foreach($items as $item)
{
$y = RSS_Tags($item, 1); // get description of article, type 1
array_push($RSS_Content, $y);
}
}
function RSS_Retrieve($url)
{
global $RSS_Content;
$doc = new DOMDocument();
$doc->load($url);
$channels = $doc->getElementsByTagName("channel");
$RSS_Content = array();
foreach($channels as $channel)
{
RSS_Channel($channel);
}
}
'http : // www.ryanhace.com/feed' url은 404일까요? –
바의 철자가 잘못되었습니다. http://www.ryanhache.com/feed – Jeff
여기에 괜찮습니다. 실제 출력과 예상 출력은 무엇입니까? –