2013-01-05 10 views
1

저는 PHP로 프로그래밍하기가 매우 쉽습니다. 몇 가지 간단한 문제가있을 수 있지만 아직 답변을 찾지 못했습니다. 태그 사이에 텍스트를 가져 오기 위해 PHP를 사용하고 Simple HTML DOM을 사용하고 싶습니다. 내 코드는 다음과 같습니다PHP로 HTML 태그에서 텍스트 가져 오기

$html = file_get_contents($base_url . $menu_url); 
//print($html); 

$students = array(); 

foreach($html->find('a') as $element) { 
    $students[] = $element->plaintext; 
} 

하지만이 코드를 실행할 때 나에게 준다 : 저를 정정 할 수

PHP Fatal error: Call to a member function find() on a non-object in <location> on line <x> 

명확한 마음을?

+0

'$ html' 문자열이 있지만 simple_html_dom 개체를 생성하지 않았습니다. –

+0

['file_get_contents'] (http://us.php.net/file_get_contents)는 문자열을 반환합니다. 이 문자열로부터 간단한 HTML DOM 객체를 생성해야합니다.이 객체는 Google에 따라 ['file_get_html'] (http://simplehtmldom.sourceforge.net/manual.htm)을 사용하여 완성됩니다. – DCoder

+0

개체를 만드는 방법에 대한 간단한 예는 http://stackoverflow.com/questions/7521507/simple-html-dom-gets-only-1-element를 참조하십시오. –

답변

관련 문제