无法使用PHP提取HTML数据

  • 本文关键字:提取 HTML 数据 PHP php
  • 更新时间 :
  • 英文 :


我试图从html页面中检索值,但在PHP中遇到了未定义的偏移量错误。我正在尝试根据日期获取第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
$dd = '07/Nov/2018';
echo "<pre>";
$rec = (explode("<tbody>", $page));
echo $rec[1];
$split= explode("$dd", explode("<tbody>", $page)[1]);
print_r($split);

添加了少量代码调试接下来的步骤u需要将所有td标签转换为数组。HTML表到数组PHP

最新更新