Php converts the br line breaks in html to line breaks in text input. PHP has a very good function: nl2br (), which converts the line break in the text box to the br on the HTML page. but how can we convert the br line break in html to the line break in the text box? PHP has a very good function: nl2br (), which converts the line feed in the text box to
But how to implement
How about converting a line break to a line break in the text box? The following methods can help you solve this problem.
In PHP
Line breaks are converted to line breaks in the text box:
function br2nl($text){ return preg_replace('/
/i','',$text);}
Or:
function br2nl($text){ $text=preg_replace('/
/i',chr(13),$text);return preg_replace('/ /i',' ',$text);}
In JS
Line breaks are converted to line breaks in the text box:
function br2nl(txt){ var re=/(
|
|
|
)/g; var s=txt.replace(re,"\n"); return s; }
Articles you may be interested in
- Php converts all-round characters in a string to half-width characters.
- PHP compresses html webpage code (clear spaces, line breaks, tabs, comment tags)
- Php converts multiple consecutive spaces in a string into one.
- Js restrictions: only English letters and numbers can be entered. Chinese characters and other special characters cannot be entered.
- PHP compresses html webpage code to reduce the amount of network data transmitted, clear spaces, tabs, and comment mark
- A classic php Tutorial book recommended for php beginners
- Summary of methods for saving arrays as text formats in php
- Php determines whether the string is full of English, pure Chinese, and a combination of Chinese and English
Transform (), convert the line feed in the text box to the br/in the HTML page, but how can we convert the br/line break in the html to the line break in the text box ?...