나는이 HTML있어 :특정 클래스와 DIV를 얻는 방법?
<div class="hello top">some content</div>
<div class="hello top">some content</div>
<div class="hello">some content</div>
<div class="hello">some content</div>
<div class="hello">some content</div>
을 ... 그리고 난 클래스 "안녕하세요"가 아니라 클래스 "정상"(나는 단지 얻기 위해 3 개 마지막으로 된 div 원하는)가 만 된 div 얻기 위해 노력하고 있어요 .
Filter Description
[attribute] Matches elements that have the specified attribute.
[!attribute] Matches elements that don't have the specified attribute.
[attribute=value] Matches elements that have the specified attribute with a certain value.
[attribute!=value] Matches elements that don't have the specified attribute with a certain value.
[attribute^=value] Matches elements that have the specified attribute and it starts with a certain value.
[attribute$=value] Matches elements that have the specified attribute and it ends with a certain value.
[attribute*=value] Matches elements that have the specified attribute and it contains a certain value.
당신은 사용할 수 있습니다 :이 테이블 (Supports these operators in attribute selectors)에 따르면
foreach($html->find('div[class="hello"], div[class!="top"]') as $element) {
// some code...
}
무엇이 문제입니까? –
게시 된 코드가 작동하지 않았습니다. 나는 해결책을 찾는 것을 시도하고있다. 나는 이것에 대해 문서에서 아무 것도 발견하지 못했다. – Manny
단순한 경우 만 처리 할 수 있기 때문에 simple-html-dom이라고합니다. phpquery 또는 DOMXPath를 시도하십시오. – pguardiario