2011-04-03 53 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); 
...