JavaScript替换< br>与\ n [英] JavaScript replace <br> with \n

查看:90
本文介绍了JavaScript替换< br>与\ n的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚使用JavaScript和PHP在MySQL数据库中存储了一段文本,并用<br />替换了\n,我现在遇到的问题是当我尝试使用PHP检索文本时将其打印出来作为; <br />

I have just stored a paragraph of text in a MySQL database using JavaScript and PHP and replaced \n with <br />, the problem I'm now having is when I try and retrieve the text using PHP it prints it out as; <br />

Dear Sir/Maddam<br />This is a letter concerning the following;<br />I would like to.... 

推荐答案

好吧,显而易见的解决方案是首先不将\n替换为<br />.

Well, the obvious solution is to just not replace \n with <br /> in the first place.

我不知道您要用哪种语言来消除...中的损害

I don't know what language you're trying to reverse the damage in...

// PHP:
$out = preg_replace("/<br ?\/?>/i","\n",$in);

// JS:
out = input.replace(/<br ?\/?>/ig,"\n");

这篇关于JavaScript替换&lt; br&gt;与\ n的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆