简体   繁体   English

隐藏textarea中的HTML标签

[英]Hide HTML tags from textarea

I'm working on email system in my project(PHP/MySql). 我正在我的项目(PHP / MySql)中处理电子邮件系统。 In my email forward form I have a text area where I'm including the following data as gmail and yahoo is doing. 在我的电子邮件转发表单中,我有一个文本区域,其中包括以下数据,例如gmail和yahoo。

---------- Forwarded message ----------
From: <testfrom@yahoo.com>
Date: Mon, Jan 9, 2014 at 10:48 PM
Subject: Order Confirmation
To: testto@gmail.com

I'm using echo "\\n"; 我正在使用echo "\\n"; for line breaking in the above data. 用于上述数据中的换行。 When I forward this data in email, It send as one row instead of sending as the above format. 当我通过电子邮件转发此数据时,它以一行形式发送,而不是以上述格式发送。 Can anyone help me how to send it in exactly the same format. 谁能帮我如何以完全相同的格式发送它。

Note : I try to user <br> for line breaking but in that case it send <br> also in email. 注意:我尝试使用<br>换行,但在这种情况下,它也会通过电子邮件发送<br>

Use nl2br for your message. 使用nl2br作为您的消息。 This will convert all \\n to <br/> . 这会将所有\\n转换为<br/>

Something like: 就像是:

$message = $_POST['message'];
mail('email@example.com', 'subject', nl2br($message));

My only assumption that new line symbols are present in an email, you just don't see them. 我唯一的假设是电子邮件中存在新的行符号,但您根本看不到它们。

For example, if you create php script: 例如,如果您创建php脚本:

<?php
echo "hello \n world";

and open it in a browser, you will not be able to view new line, because browser doesn't handle \\n symbol as line break. 并在浏览器中打开它,您将无法查看新行,因为浏览器无法将\\n符号作为换行符处理。

You will only see line breaks if you view the source of the page (by hitting CTRL+U in Chrome and Firefox, don't know about other browsers). 如果您查看页面的源代码,则只会看到换行符(通过在Chrome和Firefox中按CTRL+U ,不知道其他浏览器)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM