2011-04-13 91 views
1

最近我们的主机禁用allow_url_fopen,它似乎simplehtmldom需要它打开我看到一个工作与本站allow_url_fopen arround simplehtmldom.sourceforge.net ... aq.htm#主机,“使用卷曲获得页面,然后调用“str_get_dom”创建DOM对象“。但仍然没有运气。你能告诉我,如果我做得对吗?还是我错过了什么?使用卷曲与simplehtmldom

<?php 
$curl = curl_init(); 
curl_setopt($curl, CURLOPT_URL, 'www.weather.bm/'); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10); 
$str = curl_exec($curl); 
curl_close($curl); 
$html= str_get_html($str); 
?> 
<?php 
$element = $html->find("div"); 
$element[66]->class = "mwraping66"; 
foreach($html->find('.mwraping66 img') as $e) 

$doc = phpQuery::newDocumentHTML($e); $containers = pq('.mwraping66', $doc);  
foreach ($containers as $container) {  $div = pq('img', $container);  
$div->eq(1)->removeAttr('style')->addClass('thumbnail')->html(pq('img', $div->eq(1))- >removeAttr('height')->removeAttr('width')->removeAttr('alt')); 
} print $doc; 
?> 
<?php 
$element = $html->find("div"); 
$element[31]->class = "mwraping31"; 
foreach($html->find('.mwraping31') as $e) 
echo $e->plaintext; 
?>................................. 

相比:

<?php 
include('simple_html_dom.php'); 
include ('phpQuery.php');  
// Create DOM from URL 
$html = file_get_html('www.weather.bm/'); 
?> 
<?php 
$element = $html->find("div"); 
$element[66]->class = "mwraping66"; 
foreach($html->find('.mwraping66 img') as $e)..... 

感谢您的帮助

+0

你可能可以通过.htaccess重新启用allow_url_fopen。至于你的卷曲片段,你应该传递一个完整的http:// url到CURLOPT_URL,而不仅仅是一个域名。 – mario 2011-04-13 17:55:19

+0

我试过.htaccess,但没有工作看来我们的主机永久禁用它,至于http://我只是忘了将它包含在后遗憾。 – cooldude 2011-04-13 18:01:30

+0

我也有同样的疑问......如果有人知道答案请发布 – Eka 2012-04-11 10:44:02

回答

1

我知道这是为时已晚来回答这个查询,但我发现在这个论坛类似的问题和答案..这是该链接到Using simple html dom ..我不确定这是否会回答您的查询,因为我也是新来的DOM.try使用这个修改simple_html_dom.php文件http://webarto.com/82/php-simple-html-dom-curl它使用curl而不是file_get_content;这个文件正在为我工​​作,它的用法也与原来的一样simple_html_dom.php