我正在尝试从html页面检索值,但是在PHP中却出现了Undefined offset错误。我试图根据日期获得第4个值。
HTML Output:
<table width="438" border="1" bordercolor="#0066FF" cellspacing="0" cellpadding="0" class="gold-table" style=" line-height: 30px;
text-align: center;">
<tbody><tr style="font-weight:bold;" align="center">
<td>Date</td>
<td> 1 Item</td>
<td> 2 Item.</td>
<td> 3 Item.</td>
<td> 4 Item.</td>
</tr>
<tr>
<td>07/Nov/2018</td>
<td>10</td>
<td>20</td>
<td>30</td>
<td>40</td>
</tr>
PHP Code:
$split= explode("$dd", explode("<tbody>", $page)[0])[1];
echo $split;
$dd is todays date 07/November/2018 and $page is my testhtml page
Expected Output 07/Nov/2018 40
答案 0 :(得分:0)
$dd = '07/Nov/2018';
echo "<pre>";
$rec = (explode("<tbody>", $page));
echo $rec[1];
$split= explode("$dd", explode("<tbody>", $page)[1]);
print_r($split);
添加了一些调试代码 下一步,您需要将所有td标签转换为数组。 HTML table to array PHP