2011-04-13 33 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