2012-08-31 37 views

回答

3
<?php 
    Class A 
    { 
     private $simpleHTML; 

     function __construct() 
     { 
      $this->simpleHTML = new simple_html_dom(); 
      //now you can call all simple html functions using $this->simpleHTML->.. 
     } 

     //define file_get_html as a class method. You can call this as 
     // $x = new A(); 
     //$x->file_get_html..(externally) or $this->file_get_html(.. (internally) 
     function file_get_html($url, 
         $use_include_path = false, 
         $context=null, $offset = -1, 
         $maxLen=-1, $lowercase = true, 
         $forceTagsClosed=true, 
         $target_charset = DEFAULT_TARGET_CHARSET, 
         $stripRN=true, 
         $defaultBRText=DEFAULT_BR_TEXT) 
     { 
      // We DO force the tags to be terminated. 
      $dom = new simple_html_dom(null, $lowercase, $forceTagsClosed, $target_charset, $defaultBRText); 
      // For sourceforge users: uncomment the next line and comment the retreive_url_contents line 2 lines down if it is not already done. 
      $contents = file_get_contents($url, $use_include_path, $context, $offset); 
      // Paperg - use our own mechanism for getting the contents as we want to control the timeout. 
      //$contents = retrieve_url_contents($url); 
      if (empty($contents)) 
      { 
       return false; 
      } 
      // The second parameter can force the selectors to all be lowercase. 
      $dom->load($contents, $lowercase, $stripRN); 
      return $dom; 
     } 
    } 
?> 
+0

简单的html dom有'function file_get_html()'ouside类simple_html_dom。我必须打电话给它! '简单的html dom'是一个自定义库,用于php –

+0

我不知道我是否正确理解你,但是如果库定义为一个类,那么可以在类A的构造函数中实例化该类的对象,然后调用它作为班级的一员吗? – raidenace

+0

我在我更新的问题中发布了simple_html_dom文件。请检查一下!感谢您的帮助!:D –

相关问题