簡體   English   中英

如何在兩個標簽之間獲取元素Simple Html Dom

[英]How to get elements between two tags Simple Html Dom

這是我的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>

我正在使用Simple Html Dom php庫進行報廢。 我想用他們的錨標簽廢棄<b>標簽。 每個<b>元素都有<a>錨點集。 所以我想這樣廢棄

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

這就是我在做的事情。 首先,我躲過所有<br>標簽,然后在循環中的所有<b>標簽的話,我想獲得的下一個兄弟姐妹<b>由$ B-> NEXT_SIBLING(標簽),但其不逃避,因為工作<br>的標記指數元素未更新。 這是我的代碼

$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;

    }

由報廢請幫我<b>與他們<a>另一個策略標簽。 謝謝

我不知道是否還有其他更簡單的方法。 但只要每個<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
        )

)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM