HTML in CSV in PHP konvertieren?

Ich habe eine HTML-Tabellenstruktur wie diese;

            <tr style="font-weight: bold">
                <td>ID</td>
                <td>Navn</td>

                <td>Adresse</td>
                <td>By</td>
                <td>Post nr</td>
                <td>E-mail</td>
                <td>Telefon</td>
                <td>Status og dato</td>
                <td>Dropdown info</td>
                <td>Produkt info</td>
                <td>Buydate</td>
                <td>Ref nr. (3 første cifre)</td>
            </tr>
                    <tr>
                <td>40563</td>
                <td>Firstname Lastname</td>

                <td>Address</td>
                <td>Copen</td>
                <td>2100</td>
                <td>[email protected]</td>
                <td>123123</td>
                <td>Ikke indløst</td>
                <td>EEE-BBB</td>
</tr>

Ich möchte dies in eine CSV / Excel-Datei von PHP konvertieren.

Also ist jeder eine Zeile in Excel, und jeder ist eine Zelle in der Zeile,

Bitte wie geht das

Ich habe recherchiert und gefundenHTML-Tabelle mit PHP automatisch in eine CSV konvertieren? Aber die Antwort funktioniert bei mir nicht richtig. Ich erhalte alle Zellenergebnisse in einer "Zelle", sodass jede Zeile nur eine Zelle enthält.

Dies ist, was ich versucht habe;

        $html = str_get_html($table);



        header('Content-type: application/ms-excel');
        header('Content-Disposition: attachment; filename=sample.csv');

        $fp = fopen("php://output", "w");

        foreach($html->find('tr') as $element)
        {
            $td = array();
            foreach( $element->find('td') as $row)  
            {
                $td [] = $row->plaintext;
            }
            fputcsv($fp, $td);
        }


        fclose($fp);
        exit;

Wobei $ table das obige HTML ist. Mit einfachen HTML-Dom-Plugin

Antworten auf die Frage(3)

Ihre Antwort auf die Frage