How can nl2br function in PHP be used to handle line breaks in text output?
When outputting text in PHP, line breaks entered by the user may not be displayed correctly in the browser. The nl2br function in PHP can be used to convert newline characters (\n) to HTML line breaks (<br>) so that the text is displayed with proper line breaks.
<?php
$text = "This is a text with \n line breaks.";
echo nl2br($text);
?>
Keywords
Related Questions
- How can placeholders be used in PHP scripts to handle files with dynamic names, such as daily backups?
- What are the potential issues with comparing file contents in PHP, and how can they be resolved efficiently?
- Welche Best Practices sollten beachtet werden, um Textausgaben durch Variablen in PHP korrekt zu formatieren?