Home  >  Article  >  Backend Development  >  Convert br newline character in html to newline character in text input in php_PHP tutorial

Convert br newline character in html to newline character in text input in php_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:12:38707browse

The following methods will help you solve this problem.

The PHP version converts the
line breaks in html to line breaks in the text box:

Copy code The code is as follows:

function br2nl($text){
return preg_replace('/
/i','',$text);
}

or:

Copy code The code is as follows:

function br2nl($text){
$text=preg_replace('/< ;br\s*?/??>/i',chr(13),$text);
return preg_replace('/ /i',' ',$text);
}

The JS version converts the
line breaks in html to line breaks in the text box:

Copy code The code is as follows:

function br2nl(txt){
var re=/(
|
|
|
)/g;
var s=txt.replace(re,"n");
return s;

http://www.bkjia.com/PHPjc/326703.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326703.htmlTechArticleThe following methods will help you solve this problem. PHP version converts br/line breaks in html to line breaks in text boxes: Copy code The code is as follows: function br2nl($text){ ret...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn