How can PHP be used to extract content from an HTML table and format it with specific line breaks?

To extract content from an HTML table using PHP, you can use the DOMDocument class to parse the HTML and then loop through the table rows to extract the data. To format the content with specific line breaks, you can concatenate the extracted data with the desired line break character.

$html = '<table>
            <tr>
                <td>Row 1, Column 1</td>
                <td>Row 1, Column 2</td>
            </tr>
            <tr>
                <td>Row 2, Column 1</td>
                <td>Row 2, Column 2</td>
            </tr>
        </table>';

$dom = new DOMDocument();
$dom->loadHTML($html);

$table = $dom->getElementsByTagName('table')->item(0);
$rows = $table->getElementsByTagName('tr');

foreach ($rows as $row) {
    $cells = $row->getElementsByTagName('td');
    foreach ($cells as $cell) {
        echo $cell->nodeValue . "<br>";
    }
    echo "<br>";
}