PHP nl2br
The PHP nl2br function will add HTML line break tags before the "line" in the string <br> to allow the browser to display line breaks correctly, instead of linking each line together. Usually used when the input terminal enters the textarea in the text input field of the webpage to enter a text paragraph containing line breaks. After it is stored in the database, the symbol representing the line break such as "\n" will also be stored in the database, but when PHP is from the database When the data is read out and displayed on the web page, it will not wrap automatically. In this case, the "\n" of the string must be converted into HTML newline tags using the nl2br function .
PHP nl2br basic syntax
nl2br( $string )
The string $string in the grammar parentheses is a required item, which is the string to be converted. The newline symbols that nl2br can determine are such as \r\n , \n\r , \n and \r . When these symbols are used, nl2br will convert them into <br>, <br/> or </br> tags and return the conversion result.
PHP nl2br example
$new_string = "Welcome to Wibibi.\nIt was a very nice day.";
echo nl2br($new_string);
?>
It was a very nice day.
It was a very nice day.
Post a Comment
0 Comments