2012-03-30 2 views
0

의 형제 자매를 얻으려면 어떻게 이러한 태그를 가지고있다. PHP의 각 "항목"클래스 사이에 모든 내용을 가져올 수 있습니까? simple_html_dom_parse 또는 XPath를 사용 하시겠습니까?여러 클래스

+0

정확히 무엇을 하시겠습니까? 그것은 내게 분명하지 않다 - 당신이 예를 게시 할 수 있습니까? 첫 번째 항목과 마지막 항목 사이의 모든 요소를 ​​원하십니까? – MiMo

+0

아니요,

...
이 첫 번째 구분 기호이고 내가 얻고 자하는 내용의 첫 번째 줄임을 나타내는 그림입니다. – Panagiotis

답변

0

이 당신이 얻을하려는 것입니다 추측 :

<?php 
// set up to parse our input 
$dom = new DOMDocument(); 
$dom->loadHTMLFile("./input.html"); 
$xpath = new DOMXPath($dom); 

// initialize array to put items in and initialize an item 
$list = array(); 
$item = array(); 

$divs = $xpath->query("//div"); 
echo "len: {$divs->length}\n"; 
foreach ($divs as $div) { 
    $class = $div->getAttribute("class"); 

    // each time we see an entry, add the item we've collected 
    if ($class == "entry") { 
    if (count($item) > 0) $list[] = $item; 
    $item = array(); 
    } 

    // otherwise add to the item we're working on 
    else { 
    $item[$class] = $div->childNodes->item(0)->nodeValue; 
    } 
} 

// pick up the last item we were working on 
$list[] = $item; 

// and print the result 
var_dump($list); 
?> 
+0

고마워요! 그것은 내가 원하는 것입니다. – Panagiotis

+0

위대한! 내가 도울 수있어서 기뻐. – dldnh