我有ClassA
类,并希望在此类中使用simple_html_dom的函数。我怎样才能做到这一点? 这是simple_html_dom类http://www.megafileupload.com/en/file/366382/simple-html-dom-rar.html如何获得simple_html_dom函数的实例在类中使用
1
A
回答
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 –
相关问题
- 1. 如何在Extjs中获得类实例?
- 2. 如何在Symfony2的实体类中获得内核的实例
- 3. 如何获得一个类的实例?
- 4. 如何获得一个类的实例?
- 5. 如何获得类的实例
- 6. 如何使用表函数获得R中的比例?
- 7. 如何获得MBean绑定类实例
- 8. 如何获得ES6类实例
- 9. 如何使用'函数处理'样式函数实例化类?
- 10. 如何获得使用ctags的C++类实例?
- 11. 如何获得在类中确定的对象的实例
- 12. 使用函数创建类的实例。
- 13. 如何使用函数的monoid实例?
- 14. 如何在JavaScript中调用实例化类的函数?
- 15. 如何调用类函数中的相同类实例functionin swift
- 16. 如何在类的成员函数中返回类实例?
- 17. 如何在类实例中调用常用函数?
- 18. 如何获取Swift 4中的实例类和调用类函数?
- 19. 如何获得Hadoop中的JobTracker实例?
- 20. 如何在Django的ModelForm获得实例
- 21. 如何获得任意类的实例的计数?
- 22. simple_html_dom类,实际上明文函数返回的是什么?
- 23. Objective-c:如何在类方法中获得Class实例
- 24. 如何在WEKA中使用k-means聚类来获得异常实例?
- 25. 如何在Ruby中获取类实例?
- 26. 如何在类构造函数中存储实例引用
- 27. 如何在使用ProcessBuilder实例化新JVM实例中的类时传递构造函数的参数?
- 28. 如何从非实例类运行实例的方法/函数?
- 29. 使用Simple_Html_Dom查找函数PHP
- 30. 如何在函数内部使用线程实例函数?
'类A {$公众DOM的链接;函数__construct(){$ this-> dom = new DOMDocument; }}' – Yang
谢谢大家,但我需要做的事情我发表在我的评论下面 –