What function can be used to convert line breaks in text to HTML line breaks in PHP?
To convert line breaks in text to HTML line breaks in PHP, you can use the nl2br() function. This function takes a string as input and converts any newline characters (\n) to HTML line breaks (<br>). This is useful when displaying text from a database or form input on a webpage, as HTML line breaks are necessary for formatting the text correctly.
$text = "Hello\nWorld!";
echo nl2br($text);
Keywords
Related Questions
- What are the advantages of declaring and initializing variables in PHP, considering the potential for notice messages and security vulnerabilities?
- How can PHP be used to display live upload progress for users on a website?
- How can the code be modified to correctly calculate the total sum of the values queried from the database?