PHP has a very good function: NL2BR (), the text box to convert the line to the HTML page
, but how to implement the HTML
is the newline character converted to a line break in a text box? Here are a few ways to help you solve this problem.
The PHP version adds the HTML
Line breaks convert to newline characters in text boxes:
function Br2nl ($text) { return preg_replace ('//I
', ' ', $text);
}
Or:
function Br2nl ($text) { $text =preg_replace ('//I
', CHR), $text), return preg_replace ('//I ', ', $ text);}
JS version will be in the HTML
Line breaks convert to newline characters in text boxes:
function br2nl (txt) { var re=/(
|
|
|
)/g; var s=txt.replace (Re, "\ n"); return s; }
Articles you may be interested in
- PHP converts full-width characters in a string to half-width characters
- PHP compressed HTML page code (clear spaces, line breaks, tabs, comment markers)
- PHP converts consecutive spaces in a string to a space
- JS limit can only input English letters and numbers, can not input Chinese and other special characters of the method
- PHP compressed HTML page code reduces network data transfer, clear spaces, tabs, comment tags
- A PHP classic tutorial book recommended for beginners in PHP
- Summary of methods used by PHP to save arrays as text formats
- PHP to determine whether the string is in English, pure Chinese, the method of combination of English
http://www.bkjia.com/PHPjc/764110.html www.bkjia.com true http://www.bkjia.com/PHPjc/764110.html techarticle PHP has a very good function: NL2BR (), the text box in the line to convert to the HTML page br/, but how to implement the HTML of the BR/newline character into a text box line break? ...