Convert br newline character in html to newline character in text input in php

高洛峰
Release: 2016-12-24 15:55:45
Original
1983 people have browsed it

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

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

function br2nl($text){
    return preg_replace(&#39;/<br\\s*?\/??>/i&#39;,&#39;&#39;,$text);
}
Copy after login

或者:

function br2nl($text){
    $text=preg_replace(&#39;/<br\\s*?\/??>/i&#39;,chr(13),$text);
 return preg_replace(&#39;/ /i&#39;,&#39; &#39;,$text);
}
Copy after login

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

function br2nl(txt){
    var re=/(<br\/>|<br>|<BR>|<BR\/>)/g;
    var s=txt.replace(re,"\n");
    return s;                                  
}
Copy after login


更多php中将html中的br换行符转换为文本输入中的换行符相关文章请关注PHP中文网!


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