我正在制作一个用于保存数据的 php 应用程序,它使用表格内的表格,我想使用 PHP 将数据从表格保存到 mysql。
使用 file_get_contents 将 html 表解析为 php 数组 我正在解决这个问题,但在此 DOM 加载另一个文件,但我的表在同一个文件中。
有人可以建议我怎么做吗?
我正在制作一个用于保存数据的 php 应用程序,它使用表格内的表格,我想使用 PHP 将数据从表格保存到 mysql。
使用 file_get_contents 将 html 表解析为 php 数组 我正在解决这个问题,但在此 DOM 加载另一个文件,但我的表在同一个文件中。
有人可以建议我怎么做吗?
我可以想到两种方法:
1 - 您可以将表定义为变量,并在 PHP 块内回显它,以便您拥有用于解析的数据:
<?php
// define the table with heredoc
$data = <<<HTML
<table>
...
</table>
HTML;
// print the table
echo $data;
// follow the instructions from your link here
parseTable($data);
2 - 您还可以使用输出缓冲区获取数据:
<?php
// start a buffer
ob_start();
?>
<table>
...
</table>
<?php
// get the table in a variable
$data = ob_get_contents();
// flush the buffer to output
ob_end_flush();
// follow the instructions from your link here
parseTable($data);