2014-10-15 2 views
0

이 오류는 대머리가됩니다! 작동하지 않는 코드와 작동하는 코드가 있습니다. 문제가 무엇인지 모릅니다.Simple_html_domload_file 함수가 작동하지 않습니다.

오류 메시지는 다음과 같습니다 내 내 비 작동 코드의 바닥을 향해

PHP Fatal error: Call to a member function find() on a non-object

보세요. 해당 코드의

의 선은 다음과 같습니다

$post_link = $item->get_link(); 
$htmlDOM->load_file($post_link); 
$image = $htmlDOM->find('img', 0); 
if ($image->src) { 
    echo '<media:thumbnail url="' . $image->src . '" width="320" />'; 
} 

근무 코드 :

<?php 
// Create DOM from URL or file 
include_once('simple_html_dom.php'); 
include_once('functions.inc'); 

$html = new simple_html_dom(); 
$html->load_file('http://themaroontiger.com/an-advantageous-affair/'); 
$image = $html->find('img', 0); 
if ($image->src) { 
    echo '<media:thumbnail url="' . $image->src . '" width="320" />'; 
} 
exit; 
?> 

없음 작업 코드 :

<?php 
header("Content-Type: application/rss+xml; charset=UTF-8"); 
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; 
?> 
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:media="http://search.yahoo.com/mrss/"> 
<channel> 
<title>Maroon Tiger Feed</title> 
<link>http://www.webmaster-source.com</link> 
<description> 
Maroon Tiger Feed 
</description> 
<language>en-us</language> 
<? 
include_once('simple_html_dom2.php'); 
include_once('simplepie.inc'); 
include_once('functions.inc'); 

// MAIN BEGIN 
$feed = new SimplePie(); // Create a new instance of SimplePie 

$htmlDOM = new simple_html_dom(); 
$feed->set_feed_url(array(
     'http://themaroontiger.com/feed/' 
)); 

$feed->enable_cache('false'); //Do we cache 
$feed->set_cache_duration(600); //The cache duration 

//$feed->enable_xml_dump(isset($_GET['xmldump']) ? true : false); 

$success = $feed->init(); // Initialize SimplePie 

$feed->handle_content_type(); // Take care of the character encoding 
?> 

<? if ($success): ?> 
<? $itemlimit=0; ?> 

<? foreach($feed->get_items() as $item): ?> 
<? if ($itemlimit==20) { break; } ?> 
<item> 
<title><?= decode_entities($item->get_title()); ?> </title> 
<link><?= $item->get_permalink(); ?></link> 
<dc:creator> 
<? 
if ($author = $item->get_author()) 
     { 
       echo $author->get_name(); 
     } 
?> 
</dc:creator> 
<category><? if ($the_category = $item->get_category()) { 
       echo $the_category->get_label(); 
      } else { 
       echo 'Facebook Feed'; 
      };?> 
</category> 
<description><![CDATA[ 
<? echo $item->get_description(); ?> 
]]></description> 
<guid isPermaLink="false"><? echo $item->get_id(); ?></guid> 
<pubDate><? echo $item->get_date('D, d M Y H:i:s T'); ?></pubDate> 
<? 
$post_link = $item->get_link(); 
$htmlDOM->load_file($post_link); 
$image = $htmlDOM->find('img', 0); 
if ($image->src) { 
    echo '<media:thumbnail url="' . $image->src . '" width="320" />'; 
} 
?> 
</item> 
<? $itemlimit++ ?> 
<? endforeach; ?> 
<? endif; ?> 
</channel> 
</rss> 

답변

0

그것은 당신이 어쩌면, 피드를 통해 반복되는 것 같습니다 당신이 읽으려는 링크 중 일부는 유효하지 않고 어떤 검사도하지 않고 읽으려고하기 때문에, th 왜 오류 메시지가 표시 될 수 있습니다. 그래서 $ htmlDOM-> load_file ($ post_link); 계속하기 전에 파일이로드되었는지 확인하십시오.

관련 문제