2009-12-22 63 views

回答

4

通過查看代碼,它應該是通過使用上下文可能流,是這樣的:在php.ini

$context = stream_context_create(); 
stream_context_set_params($context, array('user_agent' => 'UserAgent/1.0')); 
file_get_html('http://www.google.com/', 0, $context); 

另外,您還可以設置默認值。

10

感謝米哈爾Čihař,你是對的 我只是做了在simple_html_dom類的LOAD_FILE()函數的一些變化和它的工作

// load html from file 
    function load_file() { 
     $args = func_get_args(); 
     // Added by Mithun 
     $opts = array(
      'http'=>array(
       'method'=>"GET", 
       'header'=>"Accept-language: en\r\n" . 
       "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6\r\n". 
       "Cookie: foo=bar\r\n" 
      ) 
     ); 
     $context = stream_context_create($opts); 
     $args[1] = FALSE; 
     $args[2] = $context; 
     // End Mithun 
     $this->load(call_user_func_array('file_get_contents', $args), true); 
    } 
+0

HI大額牛,我需要你的幫助。我如何聯繫你 – 2015-06-14 02:44:13

+0

推特:@mithunp – 2015-07-21 12:11:06

+0

你是否刪除了最後一行://如果我們無法正確加載dom,則拋出一個錯誤。 (($ error = error_get_last())!== null){ \t \t \t $ this-> clear(); \t \t \t return false; \t \t} \t} – cikatomo 2015-09-14 01:36:47

相關問題