クラスがClassA
あり、このクラスで simple_html_dom の関数を使用したいと考えています。どうやってやるの?これは simple_html_dom クラスのリンクですhttp://www.megafileupload.com/en/file/366382/simple-html-dom-rar.html
質問する
439 次
1 に答える
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;
}
}
?>
于 2012-08-31T04:11:24.800 に答える