How can one prevent long strings from distorting the layout in PHP when displaying text from a database within a table?
Long strings can distort the layout in PHP when displaying text from a database within a table by causing the table cells to expand beyond their intended width. To prevent this, you can use the CSS property `word-wrap: break-word;` to force long strings to wrap within the table cell.
echo '<table>';
while($row = mysqli_fetch_assoc($result)) {
echo '<tr>';
echo '<td style="word-wrap: break-word;">' . $row['long_text_column'] . '</td>';
echo '</tr>';
}
echo '</table>';
Keywords
Related Questions
- How can PHP handle escaping magic_quotes_gpc, decoding HTML entities, and converting special characters in form inputs?
- Are there any potential pitfalls to be aware of when using substr() and strlen() in PHP?
- What are the benefits of using frameworks for PHP API development, especially in terms of authentication implementation?