Home  >  Article  >  Web Front-end  >  Convert br newline character in html to newline character in text input in php

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

高洛峰
高洛峰Original
2016-12-24 15:55:451939browse

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

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

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

或者:

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

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

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


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


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