PHP Simple Html Dom ile tablodan veri çekmek
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>
Sorgu bir türlü istediğim gibi çalışmıyor. İstediğim 2021/10 ait veri varsa aşağıdaki çalıştırsın, yoksa durdusun. Sanırım mantığı anlatabildim.
Belirlediğim tarihler arasında istediğim verileri toplamak
if(strstr($year, "2021/10") === false){ break; }
// Çalışacak kodlar
if($year == "2020/10"){ break; }