How to convert br newline character in html to newline character in text input_PHP Tutorial

WBOY
Release: 2016-07-13 10:31:22
Original
898 people have browsed it

PHP中的有个非常好的函数:nl2br(),将文本框中的换行转换为HTML页面的
,但是如何实现将html中的
换行符转换为文本框中的换行符呢?下面这几个方法将能够帮你解决这个问题。

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

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

或者:

function br2nl($text){
    $text=preg_replace('/<br\\s*?\/??>/i',chr(13),$text);
	return preg_replace('/ /i',' ',$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将字符串中全角字符转换为半角字符
  • PHP压缩html网页代码(清除空格,换行符,制表符,注释标记)
  • php 将字符串中的连续多个空格转换为一个空格
  • js限制只能输入英文字母和数字,不能输入中文和其他特殊字符的办法
  • PHP压缩html网页代码减小网络数据传输量,清除空格,制表符,注释标记
  • 给php初学者推荐的一本php经典教程书籍
  • php将数组保存为文本格式的方法总结
  • php判断字符串是否全英文,纯中文,中英文组合的方法

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/764110.htmlTechArticlePHP中的有个非常好的函数:nl2br(),将文本框中的换行转换为HTML页面的br /,但是如何实现将html中的br /换行符转换为文本框中的换行符呢?...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!