Skip to content
PHP Logo

What are some common text formatting options that can be stored in a PHP/SQL database?

When storing text formatting options in a PHP/SQL database, it is common to use HTML tags such as <b> for bold, <i> for italics, <u> for underline, and <p> for paragraphs. These tags can be stored as strings in the database and then applied when displaying the text on a webpage.

php
// Example of storing text with formatting options in a PHP/SQL database
$text = "<b>This is bold text</b>, <i>this is italic text</i>, and <u>this is underlined text</u>.<p>This is a paragraph.</p>";

// Store the text in the database
$sql = "INSERT INTO text_table (formatted_text) VALUES ('$text')";
$result = mysqli_query($conn, $sql);

// Retrieve the text from the database and display it on a webpage
$sql = "SELECT formatted_text FROM text_table WHERE id = 1";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);

echo $row['formatted_text'];