您的位置:首页 > 编程语言 > PHP开发

在b2core框架和simple_html_dom.php文件里面都有一个load()函数

2017-04-30 00:00 441 查看
在simple_html_dom.php文件里面,有一个load()函数的定义。

// load html from string
function load($str, $lowercase=true, $stripRN=true, $defaultBRText=DEFAULT_BR_TEXT, $defaultSpanText=DEFAULT_SPAN_TEXT)
{
global $debugObject;

// prepare
$this->prepare($str, $lowercase, $stripRN, $defaultBRText, $defaultSpanText);
// strip out comments
$this->remove_noise("'<!--(.*?)-->'is");
// strip out cdata
$this->remove_noise("'<!\[CDATA\[(.*?)\]\]>'is", true);
// Per sourceforge http://sourceforge.net/tracker/?func=detail&aid=2949097&group_id=218559&atid=1044037 // Script tags removal now preceeds style tag removal.
// strip out <script> tags
$this->remove_noise("'<\s*script[^>]*[^/]>(.*?)<\s*/\s*script\s*>'is");
$this->remove_noise("'<\s*script\s*>(.*?)<\s*/\s*script\s*>'is");
// strip out <style> tags
$this->remove_noise("'<\s*style[^>]*[^/]>(.*?)<\s*/\s*style\s*>'is");
$this->remove_noise("'<\s*style\s*>(.*?)<\s*/\s*style\s*>'is");
// strip out preformatted tags
$this->remove_noise("'<\s*(?:code)[^>]*>(.*?)<\s*/\s*(?:code)\s*>'is");
// strip out server side scripts
$this->remove_noise("'(<\?)(.*?)(\?>)'s", true);
// strip smarty scripts
$this->remove_noise("'(\{\w)(.*?)(\})'s", true);

// parsing
while ($this->parse());
// end
$this->root->_[HDOM_INFO_END] = $this->cursor;
$this->parse_charset();

// make load function chainable
return $this;

}

注意到这里,上面的一个函数通过正则表达式去掉了<script></script>标签内部的函数。如果,我们要抓取内部的<script></script>内部的内容的时候,就不能再利用框架了。

对比,我们的系统框架b2core内部也有一个加载系统的文件或类的函数load()

/* B2 系统函数
* load($path,$instantiate) 可以动态载入对象,如:控制器、Model、库类等
* $path 是类文件相对 app 的地址
* $instantiate 为 False 时,仅引用文件,不实例化对象
* $instantiate 为数组时,数组内容会作为参数传递给对象
*/

function &load($path, $instantiate = TRUE )
{
$param = FALSE;
if(is_array($instantiate)) {
$param = $instantiate;
$instantiate = TRUE;
}
$file = explode('/',$path);
$class_name = array_pop($file);
$object_name = md5($path);

static $objects = array();
if (isset($objects[$object_name])) {
if($objects[$object_name] == TRUE && $instantiate == TRUE) {
if ($param == FALSE) return new $class_name();
return new $class_name($param);
}
return $objects[$object_name];
}
require(APP.$path.'.php');
if ($instantiate == FALSE) $objects[$object_name] = TRUE;
elseif ($param) $objects[$object_name] = new $class_name($param);
else  $objects[$object_name] = new $class_name();
return $objects[$object_name];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐