【问题标题】:Getting CRLF from text input in php从 php 中的文本输入中获取 CRLF
【发布时间】:2017-08-30 21:14:22
【问题描述】:

我对 Web 开发比较陌生。我在 html 中有一个简单的文本输入和提交按钮。

<div>
<input type="text" name="sender" id="sender" class="form-control" placeholder="" />
<input type="submit" class="btn-u btn-u-small" name="send" value="Send email" />
</div>

我得到了 php 中文本输入的值和echo 它。

<?php
if(isset($_POST["send"]))
{
    echo $_POST["sender"] . " \r\nThis was a test";
}
?>

现在我在文本输入中输入\r\nUser input。我希望echo 命令看起来像:

echo "\r\rUser input." . " \r\nThis was a test."

当显示出来时,应该是这样的:

User input. This was a test.

第一个 \r\n 原样打印,只有第二个 \r\n 被解释为 CRLF

\r\nUser input. This was a test.

我试过'\r\n' "\r\n" \\r\\n,但似乎没有用。

注意:我不想要 html 中的实际换行符,我知道 html 中的换行符是&lt;br /&gt;。我想在 php 字符串中换行。

【问题讨论】:

  • 你试过echo nl2br ("User input. \n This was a test"); 吗? (在这里找到:http://stackoverflow.com/questions/12994769/how-to-add-a-line-break-within-echo-in-php
  • @danny 该代码是演示 php mail() 漏洞的示例程序的一部分。我无法在代码中添加任何其他内容。我只能通过在 html 文本输入中键入值来与之交互。
  • 好吧,html实体呢?例如&amp;#13; 换行?
  • @danny 是的,尝试过 、 等。没用。

标签: php html newline textinput


【解决方案1】:

浏览器将过滤/编码/清理您在文本字段中输入的所有内容,因此您必须找到一种方法让浏览器为您生成 CRLF。

一种方法是:

  • 使用火狐
  • 安装扩展TamperData
  • 使用它来修改您发送的文本,例如插入 %0D%0A 在 开始;这是 \r\n
  • 的 URL 编码版本

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-19
    • 2016-04-06
    • 2012-02-11
    • 2017-04-23
    • 2012-01-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多