How can PHP functions like "br2nl" and "nl2br" be used to manage line breaks in MySQL database entries effectively?

When storing text in a MySQL database, line breaks can cause issues when displaying the content on a webpage. PHP functions like "br2nl" and "nl2br" can be used to convert line breaks between HTML <br> tags and newline characters (\n) effectively. By using these functions before inserting or retrieving data from the database, you can ensure consistent formatting of line breaks in your application.

// Function to convert &lt;br&gt; tags to newline characters
function br2nl($text) {
    return preg_replace(&#039;/&lt;br\s*\/?&gt;/i&#039;, &quot;\n&quot;, $text);
}

// Function to convert newline characters to &lt;br&gt; tags
function nl2br($text) {
    return nl2br($text);
}

// Example of converting line breaks before inserting data into the database
$inputText = &quot;This is a line with &lt;br&gt; line break.&quot;;
$convertedText = br2nl($inputText);
// Insert $convertedText into the database

// Example of converting line breaks after retrieving data from the database
// Retrieve $text from the database
$retrievedText = &quot;This is a line with \n line break.&quot;;
$convertedText = nl2br($retrievedText);
// Display $convertedText on the webpage