v2.5.2
Giriş yap

PHP Simple Html Dom ile tablodan veri çekmek

siyahkalem
604 defa görüntülendi ve 2 kişi tarafından değerlendirildi

PHP Simple html dom kütüphanesini kullanarak ilgili tablodan veri çekiyorum. Ancak bir sorum var.

Tablolarda sınıf olmadığı için indeks numarasına göre veri alıyorum. Yılların günlerini almak istediğimde, "exaple: By 2021" td etiketi değil de th etiketi geldiğinde kaymalar oluyor.

Bu durumda hem yıllar hem de yıllar için gün sayısını nasıl alabilirim?

    // kodlarınız buraya eklenecek
    
    $total = 0;
 for($i = 7; $i <= 455; $i += 15){

        $year       = $html_base->find('td',$i)->plaintext;
        $days       = $html_base->find('td',$i + 2)->plaintext;

        $total += $html_base->find('td',$i + 3)->plaintext;
            if($year == "2020/11"){ break; } 

     }


<table class="resultTable table table-striped table-bordered">

    <thead style="font-size: 12px">
        <tr>
            <th scope="col">aaa</th>
            <th scope="col">aaa</th>
            <th scope="col">aaa</th>
            <th scope="col">aaa</th>
            <th scope="col">aaa</th>
            <th scope="col">aaa</th>
            <th scope="col">aaa</th>
            <th scope="col">Year / Month</th>
            <th scope="col">aaa</th>
            <th scope="col">aaa</th>
            <th scope="col">Days</th>
            <th scope="col">aaa</th>
            <th scope="col">aaa</th>
            <th scope="col">aaa</th>
            <th scope="col">aaa</th>        
        </tr>
    </thead>
    <tbody style="font-size: 12px">
        <tr>
            <td>xxx</td>
            <td>xxx</td>
            <td>xxxx</td>
            <td>xxx</td>
            <td>xxx</td>
            <td>xxxx</td>
            <td>xxx</td>
            <td>2022/01</td>
            <td>xxx</td>
            <td>xxx</td>
            <td>30</td>
            <td>xxxx</td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <th colspan="10">2022 Year</th>
            <td>yyyy</td>
            <td colspan="5">yyy</td>
        </tr>

        <tr>
            <td>xxx</td>
            <td>xxx</td>
            <td>xxxx</td>
            <td>xxx</td>
            <td>xxx</td>
            <td>xxxx</td>
            <td>xxx</td>
            <td>2021/12</td>
            <td>xxx</td>
            <td>xxx</td>
            <td>25</td>
            <td>xxxx</td>
            <td></td>
            <td></td>
            <td></td>
        </tr>

        <tr>
            <td>xxx</td>
            <td>xxx</td>
            <td>xxxx</td>
            <td>xxx</td>
            <td>xxx</td>
            <td>xxxx</td>
            <td>xxx</td>
            <td>2021/11</td>
            <td>xxx</td>
            <td>xxx</td>
            <td>25</td>
            <td>xxxx</td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td>xxx</td>
            <td>xxx</td>
            <td>xxxx</td>
            <td>xxx</td>
            <td>xxx</td>
            <td>xxxx</td>
            <td>xxx</td>
            <td>2021/10</td>
            <td>xxx</td>
            <td>xxx</td>
            <td>25</td>
            <td>xxxx</td>
            <td></td>
            <td></td>
            <td></td>
        </tr>

        <tr>
            <td>xxx</td>
            <td>xxx</td>
            <td>xxxx</td>
            <td>xxx</td>
            <td>xxx</td>
            <td>xxxx</td>
            <td>xxx</td>
            <td>2022/01</td>
            <td>xxx</td>
            <td>xxx</td>
            <td>30</td>
            <td>xxxx</td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <th colspan="10">2021 Year</th>
            <td>yyyy</td>
            <td colspan="5">yyy</td>
        </tr>
        <tr>
            <td>xxx</td>
            <td>xxx</td>
            <td>xxxx</td>
            <td>xxx</td>
            <td>xxx</td>
            <td>xxxx</td>
            <td>xxx</td>
            <td>2020/12</td>
            <td>xxx</td>
            <td>xxx</td>
            <td>25</td>
            <td>xxxx</td>
            <td></td>
            <td></td>
            <td></td>
        </tr>           

        <tr>
            <td>xxx</td>
            <td>xxx</td>
            <td>xxxx</td>
            <td>xxx</td>
            <td>xxx</td>
            <td>xxxx</td>
            <td>xxx</td>
            <td>2020/11</td>
            <td>xxx</td>
            <td>xxx</td>
            <td>25</td>
            <td>xxxx</td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <th colspan="10">2020 Year</th>
            <td>yyyy</td>
            <td colspan="5">yyy</td>
        </tr>
    </tbody>
</table>



siyahkalem
1012 gün önce

$year = $elem->children(7)->plaintext;

if(strstr($year, "2021/10")){
}else{

}

Yukarı işlemi yapmak sitediğimde strstr fonkisyonu bana true ya da false döndermiyor. Sanki eşit mi değil mi diye sorumuşum gibi davranıyor. Nedeni ne olabilir?