2012-02-23 3 views
2

PHP 간단한 DOM 파서 http://simplehtmldom.sourceforge.net/manual.htm을 사용하고 있습니다. 나는 간단한 DOM API를 문서, 나는 우리가 찾기 기능에서 여러 클래스 나 ID를 포함하여 한 번에 여러 태그를 선택할 수 있습니다 참조 읽기PHP 간단한 DOM 파서 한번에 복수의 태그를 선택하고 제거하십시오

$html = str_get_html('<div><div class="two">two</div></div>');  
$e = $html ->find('.two',0); 
$e->outertext = ''; 
echo $html ->outertext; 

을 수행하여 특정 ID로 태그를 제거 할 수 있어요하지만, 한 번에 모든 것을 어떻게 제거 할 수 있습니까?

다음을 시도했지만 작동하지 않습니다. 첫 번째 클래스 만 제거합니다. .two

$e = $html ->find('.two, .three, .four'); 
$e->outertext = ''; 
echo $html ->outertext; 

답변

-1

잘 작동합니다.

위의 코드에서 발견 한 문제점은 변수 이름과 같습니다. 콘텐츠가 $ html에 있지만 div를 찾기 위해 $ str 변수를 사용하고 있습니다.

$html = str_get_html('<div><div class="two">two</div><div class="three">thomas</div><div class="four">babu</div></div>');  
$e = $html->find('#two , #three',0); 
$e->outertext = ''; 
echo $html->outertext; 

+0

이것은 문제가되지 않습니다 있어요. 그것은 단지 오타에 불과합니다. 여기에 어떻게 내 PHP 파일 http://eprogramers.com/domparser.txt처럼 보입니다. 그것은 나를 위해 작동하지 않습니다. 내가 가지고있는대로 시험해보고 그게 효과가 있는지 알려주세요. – Pinkie

+0

안녕 핑키, 나는 "$ html-> find ('. two, .one', 0);"$ html-> find ('# two, # one', 0); 그 일. – thomasbabuj

+0

그건 작동하지 않습니다. 나에게 당신의 작업 코드를 제공 할 수 있습니까? – Pinkie

0

죄송합니다.

// Find all anchors and images with the "title" attribute 
$ret = $html->find('a[title], img[title]'); 

<div class="mainnavs"> 
    <ul> 
     <li>Tags</li> 
     <li>Users</li> 
    </ul> 
</div> 

<div class="askquestion"> 
    <ul> 
     <li> 
      Ask Questions 
     </li> 
    </ul> 
</div> 

위의 HTML의 간단한 HTML DOM 파서 문서에 따라 내가 예상 한 결과,

$result = $html->find('[.mainnavs], [.askquestion]' , 0); 
관련 문제