PHP has a very good function: nl2br (), which converts the line feed in the text box to the HTML page <br/>, but how can we convert <br/> line breaks in html to line breaks in text boxes? The following methods can help you solve this problem.
PHP converts <br/> line breaks in html to line breaks in the text box:
function br2nl($text){ return preg_replace('/<br\\s*?\/??>/i','',$text);}
Or:
function br2nl($text){ $text=preg_replace('/<br\\s*?\/??>/i',chr(13),$text);return preg_replace('/ /i',' ',$text);}
JS version converts <br/> line breaks in html to line breaks in the text box:
function br2nl(txt){ var re=/(<br\/>|<br>|<BR>|<BR\/>)/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