What function in PHP can be used to convert newline characters to HTML line breaks for displaying text from a database?
When displaying text from a database in HTML, newline characters (\n) need to be converted to HTML line breaks (<br>) in order to properly format the text with line breaks. This can be achieved using the PHP function nl2br(), which converts newline characters to <br> tags.
$text_from_database = "This is a text with\nnewline characters.";
$formatted_text = nl2br($text_from_database);
echo $formatted_text;
Related questions
-
SQL injection cross-site scripting session hijacking
-
browser preview tools PHP scripts Sublime Text
-
Apache PHP MySQL