2011-04-03 139 views
0

我正在使用https://github.com/feelinglucky/php-readability,我可以讓作者的例子工作。但是,當我創建自己的時候,它只是輸出url。有人知道我的代碼有什麼問題嗎?PHP可讀性無法正常工作

這裏是我的代碼:

<?php 
require 'lib/Readability.inc.php'; 

$source = 'http://techcrunch.com/2011/04/02/conduit-acquires-web-application-platform-wibiya-for-45-million-sources/'; 

$Readability = new Readability($source, $html_input_charset); //default charset is utf-8 
$ReadabilityData = $Readability->getContent(); 
$title = $ReadabilityData['title']; 
$content = $ReadabilityData['content']; 
?> 
<html> 
<head> 
    <title>test - <?php echo $title; ?></title> 
</head> 
<body> 
<?php 
echo "<h1>". $title."</h1> "; 
echo $content; 
?> 
</body> 
</html> 

,這是輸出我得到:

<html> 
<head> 
<title>test - </title> 
</head> 
<body> 
<h1></h1> <body contentScore="105"><p>http://techcrunch.com/2011/04/02/conduit-acquires-web-application-platform-wibiya-for-45-million-sources/</p></body> 
</body> 
</html> 

,我要找的輸出是這樣的: https://lab.gracecode.com/readability/?url=http%3A%2F%2Ftechcrunch.com%2F2011%2F04%2F02%2Fconduit-acquires-web-application-platform-wibiya-for-45-million-sources%2F

回答

4

你是應該餵它一個HTML文件。

$source = 'http://techcrunch.com/2011/04/02/conduit-acquires-web-application-platform-wibiya-for-45-million-sources/'; 

$html = file_get_contents($source);  
$Readability = new Readability($html, $html_input_charset); 
...