How can HTML tags be stored as text in a MySQL database and then displayed as HTML in a PHP script?

To store HTML tags as text in a MySQL database and then display them as HTML in a PHP script, you can use the htmlentities() function to escape the HTML tags before inserting them into the database. When retrieving the data from the database, you can use the htmlspecialchars_decode() function to convert the escaped HTML tags back to their original form for display in the PHP script.

// Inserting HTML content into the database
$htmlContent = "<p>This is some <strong>HTML</strong> content.</p>";
$escapedContent = htmlentities($htmlContent);
$sql = "INSERT INTO table_name (content) VALUES ('$escapedContent')";
// Execute SQL query to insert data

// Retrieving and displaying HTML content in PHP script
$sql = "SELECT content FROM table_name WHERE id = 1";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);
$originalContent = htmlspecialchars_decode($row['content']);
echo $originalContent;