I have a html table structure like this;
ID
-
You can load them in an array using the PHP DOM classes
$data = array();
$doc = new DOMDocument();
$doc->loadHTML($html);
$rows = $doc->getElementsByTagName('tr');
foreach($rows as $row) {
$values = array();
foreach($row->childNodes as $cell) {
$values[] = $cell->textContent;
}
$data[] = $values;
}
You can then convert that array to CSV data like in your example, or just simply build the CSV string directly in the loops.
Live example
- 热议问题