How can PHP be used to display text with paragraphs from a MySQL table?

To display text with paragraphs from a MySQL table using PHP, you can fetch the data from the database and use the nl2br() function to convert newline characters to HTML line breaks. This will ensure that paragraphs are displayed correctly on the webpage.

<?php
// Connect to MySQL database
$connection = mysqli_connect("localhost", "username", "password", "database");

// Fetch text data from MySQL table
$query = "SELECT text_content FROM table_name";
$result = mysqli_query($connection, $query);

// Display text with paragraphs
while($row = mysqli_fetch_assoc($result)) {
    echo nl2br($row['text_content']);
}

// Close database connection
mysqli_close($connection);
?>