클래스가 ClassA
이고 simple_html_dom의 함수를이 클래스에 사용하고 싶습니다. 어떻게해야합니까? 이 simple_html_dom 클래스 http://www.megafileupload.com/en/file/366382/simple-html-dom-rar.html클래스에서 simple_html_dom의 함수 인스턴스를 사용하는 방법
답변
<?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;
}
}
?>
간단한 HTML DOM은'function file_get_html()'이 클래스 simple_html_dom을 ouside 가지고있다. 나는 그것을 부르지 않아! 'simple html dom'은 PHP에 대한 커스텀 라이브러리입니다. –
정확하게 이해할 수 있을지 모르겠지만 라이브러리가 클래스로 정의되어 있다면 클래스 A의 생성자 내부에서 인스턴스화 된 클래스의 객체를 가질 수 있습니다. 그것은 클래스 권리의 일원으로서? – raidenace
업데이트 된 질문에 simple_html_dom 파일을 게시했습니다. 그것을 확인하시기 바랍니다! 도와 주셔서 감사합니다! : D –
- 1. 클래스에서 MembershipCreateStatus를 사용하는 방법
- 2. 클래스에서 멤버 함수 전문화를 사용하는 방법은 무엇입니까?
- 3. App_Code의 클래스에서 Control.GetRouteUrl을 사용하는 방법
- 4. 클래스에서 한정자 키를 사용하는 방법
- 5. 클래스에서 "openPerspectiveMenu"클래스를 사용하는 방법?
- 6. 인스턴스를 함수 인수로 전달
- 7. 함수 인터페이스 및 클래스에서 오버로딩 - 방법?
- 8. 함수 주소 또는 클래스에서 CFBundleRef를 찾는 방법
- 9. Matlab : 클래스에서 함수 가져 오기
- 10. 하위 클래스에서 함수 호출하기
- 11. 같은 클래스에서 함수 사용하기
- 12. 클래스에서 PHP 함수 사용
- 13. 다른 클래스에서 같은 함수 호출
- 14. 정적 메서드에서 sfRequest 인스턴스를 사용하는 방법?
- 15. outline-minor-mode를 사용하는 클래스에서 이맥스 축소 함수
- 16. 폼의 인스턴스를 가져 오는 함수
- 17. 자주 사용하는 함수 : 구조화하는 방법?
- 18. 함수 내에서 List.nth를 사용하는 방법
- 19. 함수 기반 인덱스를 사용하는 방법
- 20. javax.sql.DataSource의 인스턴스를 사용하는 Hibernate
- 21. 여러 IOS보기 클래스에서 Facebook 인스턴스를 유지하려면 어떻게해야합니까?
- 22. 클래스에서 선언 된 인스턴스를 전역화할 수 있습니까?
- 23. 기본 클래스에서 이벤트 핸들러를 사용하는 방법
- 24. android 자바 클래스에서 문자열 리소스를 사용하는 방법
- 25. 다른 클래스에서 선언 된 배열을 사용하는 방법
- 26. Java 클래스에서 사용하는 메소드를 결정하는 방법
- 27. 다른 클래스에서 xaml 개체를 사용하는 방법
- 28. 레일 : lib의 별도 클래스에서 도우미를 사용하는 방법
- 29. 버전이 지정된 클래스에서 NSCoder를 사용하는 방법
- 30. 반환 형식으로 System.Action을 사용하는 방법? BLL 클래스에서
'클래스 A {공공 $의 DOM의 링크입니다; function __construct() {$ this-> dom = 새 DOMDocument; }}' – Yang
고마워,하지만 아래에 내 코멘트에 게시 된 것들을 할 필요가 –