Home > Backend Development > PHP Tutorial > php中将html中的br换行符转换为文本输入中的换行符_php技巧

php中将html中的br换行符转换为文本输入中的换行符_php技巧

WBOY
Release: 2016-05-17 09:06:13
Original
905 people have browsed it

下面这几个方法将能够帮你解决这个问题。

PHP版将html中的
换行符转换为文本框中的换行符:

复制代码 代码如下:

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

或者:

复制代码 代码如下:

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

JS版将html中的
换行符转换为文本框中的换行符:

复制代码 代码如下:

function br2nl(txt){
    var re=/(
|
|
|
)/g;
    var s=txt.replace(re,"\n");
    return s;                                 
}
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template