What measures can be taken to ensure proper formatting and alignment of data in HTML tables generated by PHP scripts?

To ensure proper formatting and alignment of data in HTML tables generated by PHP scripts, you can use CSS styling to control the appearance of the table cells. You can set specific widths for columns, adjust text alignment, and apply borders or padding to cells as needed.

echo '<table style="width: 100%;">';
echo '<tr>';
echo '<th style="text-align: left;">Header 1</th>';
echo '<th style="text-align: center;">Header 2</th>';
echo '<th style="text-align: right;">Header 3</th>';
echo '</tr>';
echo '<tr>';
echo '<td style="width: 33%;">Data 1</td>';
echo '<td style="width: 33%;">Data 2</td>';
echo '<td style="width: 33%;">Data 3</td>';
echo '</tr>';
echo '</table>';