How to convert php table content to array: 1. Create a PHP sample file; 2. Convert each row and column of the HTML table to an array through the "function tdToArray($table) {...}" method That’s it.
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
How to convert the content of php table to an array?
php Regularly matches the table in the html of the web page and converts the content into an array
When connecting to JD.com vop, when JD.com returns the specification attribute, the style in html format is returned. For example
$date=' <table cellpadding="0" cellspacing="1" width="100%"border="0" class="Ptable"> <tr> <th class="tdTitle" colspan="2">主体 </th> <tr> <tr> <td class="tdTitle">品牌 </td> <td>好孩子 </td> </tr> <tr> <td class="tdTitle">主材质 </td> <td>PP </td> </tr> <tr> <td class="tdTitle">规格 </td> <td>800mm*445mm*225 </td> </tr> </table>';
the above table, the preview is
The next step is to extract, the extraction idea is to use regular expressions to convert
, |