2017-02-07 1 views
1

이 내 HTML을하는 방법을 두 태그 사이에 요소 간단한 HTML 돔

<b><font color="Red">Flash Player 720p HD Quality Online Links</font></b> 
     <br> 
     <br> 
     <a href="http://bestarticles.me/jaana-na-dil-se-door/?si=5325359" target="_blank">Jaana Na Dil Se Door 6th February 2017 Watch Online Video- Part 1</a> 
     <br> 
     <a href="http://bestarticles.me/jaana-na-dil-se-door/?si=5325360" target="_blank">Jaana Na Dil Se Door 6th February 2017 Watch Online Video- Part 2</a> 
     <br> 
     <br> 
     <b><font color="Red">Dailymotion 720p HD Quality Online Links</font></b> 
     <br> 
     <br> 
     <a href="http://bestarticles.me/jaana-na-dil-se-door/?si=k4r2rHPOgem8yAlGqjj" target="_blank">Jaana Na Dil Se Door 6th February 2017 Watch Online Video- Part 1</a> 
     <br> 
     <a href="http://bestarticles.me/jaana-na-dil-se-door/?si=k63MLC2Vq6fxsPlGqjp" target="_blank">Jaana Na Dil Se Door 6th February 2017 Watch Online Video- Part 2</a> 
     <br> 
     <br> 
     <b><font color="Red">TVLogy 720p HD Quality Online Links</font></b> 
     <br> 
     <br> 
     <a href="http://reviewtv.in/star-plus/?si=YD29025" target="_blank">Jaana Na Dil Se Door 6th February 2017 Watch Online Video- Part 1</a> 
     <br> 
     <a href="http://reviewtv.in/star-plus/?si=YD29026" target="_blank">Jaana Na Dil Se Door 6th February 2017 Watch Online Video- Part 2</a> 
     <br> 
     <br> 
     <b><font color="Red">Letwatch 720p HD Quality Online Links</font></b> 
     <br> 
     <br> 
     <a href="http://www.tellycolors.me/star-plus/?si=j3vpekz3jeiv" target="_blank">Jaana Na Dil Se Door 6th February 2017 Watch Online Video - Part 1</a> 
     <br> 
     <a href="http://www.tellycolors.me/star-plus/?si=bdjg53bz9gdi" target="_blank">Jaana Na Dil Se Door 6th February 2017 Watch Online Video - Part 2</a> 
     <br> 
     <br> 
     <b><font color="Red">Vidwatch 720p HD Quality Online Links</font></b> 
     <br> 
     <br> 
     <a href="http://hd-rulez.info/vidwatch.php?id=73sbn356g9nc" target="_blank">Jaana Na Dil Se Door 6th February 2017 Watch Online Video - Part 1</a> 
     <br> 
     <a href="http://hd-rulez.info/vidwatch.php?id=73x796cifyvq" target="_blank">Jaana Na Dil Se Door 6th February 2017 Watch Online Video - Part 2</a> 
     <br> 
     <br> 

내가 폐기에 대한 간단한 HTML 돔 PHP 라이브러리를 사용하고 있습니다. <b> 태그와 앵커 태그를 스크랩하고 싶습니다. <b> 개의 요소에는 모두 <a> 앵커 세트가 있습니다. 그래서 나는 이렇게 스크랩하고 싶습니다.

array(
     'Flash Player' => array('link1', 'link2'), 
     'Daiylymotion' => array('link1', 'link2', 'link3'), 
     etc... 
); 

그리고 이것은 제가하고있는 것입니다. 처음에는 모든 <br> 태그를 이스케이프 처리 한 다음 모든 <b> 태그를 루프 한 다음 다음 형제 인 <b> 태그를 $ b-> next_sibling()으로 태그를 가져 오려고했지만 그 태그가 작동하지 않으므로 <br> 태그 색인이 업데이트되지 않았습니다. 여기에 또 다른 전략과의 <a> 태그 <b>을 폐기하여 도와주세요 내 코드

$html = str_get_html($html); 
$content = $html->find('div.postcontent',0); 

    //escape all br 
    foreach($content->find('br') as $br){ 
     $br->outertext = ''; 
    } 

    foreach($content->find('b') as $key => $b){ 


     echo $b->plaintext; 

    } 

입니다. 고마워요

답변

0

다른 쉬운 방법이 있는지 잘 모르겠습니다. 그러나이 코드는 각 <b> 태그가 정확히 두 개의<a> 태그가있는 한 원하는 출력을 제공합니다.

$aCount = 0; 
    $result = array(); 
    foreach($content->find('b') as $key => $b){ 
     $index = $b->plaintext; 
     for($i=0;$i<2;$i++){ 
      $result[$index][] = $content->find('a',$aCount++)->href; 
     }  
    } 
    print_r($result); 

출력

Array 
(
    [Flash Player 720p HD Quality Online Links] => Array 
     (
      [0] => http://bestarticles.me/jaana-na-dil-se-door/?si=5325359 
      [1] => http://bestarticles.me/jaana-na-dil-se-door/?si=5325360 
     ) 

    [Dailymotion 720p HD Quality Online Links] => Array 
     (
      [0] => http://bestarticles.me/jaana-na-dil-se-door/?si=k4r2rHPOgem8yAlGqjj 
      [1] => http://bestarticles.me/jaana-na-dil-se-door/?si=k63MLC2Vq6fxsPlGqjp 
     ) 

    [TVLogy 720p HD Quality Online Links] => Array 
     (
      [0] => http://reviewtv.in/star-plus/?si=YD29025 
      [1] => http://reviewtv.in/star-plus/?si=YD29026 
     ) 

    [Letwatch 720p HD Quality Online Links] => Array 
     (
      [0] => http://www.tellycolors.me/star-plus/?si=j3vpekz3jeiv 
      [1] => http://www.tellycolors.me/star-plus/?si=bdjg53bz9gdi 
     ) 

    [Vidwatch 720p HD Quality Online Links] => Array 
     (
      [0] => http://hd-rulez.info/vidwatch.php?id=73sbn356g9nc 
      [1] => http://hd-rulez.info/vidwatch.php?id=73x796cifyvq 
     ) 

) 
같은 것