doupi3874 2017-04-05 10:08
浏览 134
已采纳

从PHP中的文本输入获取CRLF

I am relatively new to web development. I have a simple text input and submit button in 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>

I get the value of the text input in php and echo it.

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

Now I type User input in text input. I intend the echo command to look like:

echo "User input." . " 
This was a test."

And when displayed, should look like:

User input. This was a test.

Instead the first prints as it is and only the second is interpreted as CRLF.


User input. This was a test.

I've tried ' ' " " \\ but non seem to work.

Note: I don't want actual line break in html, I know that in html line breaks are <br />. I want a line break in php string.

  • 写回答

1条回答 默认 最新

  • duanjiagu0655 2017-04-09 11:44
    关注

    The browser is going to filter/encode/sanitize everything you enter in the text field, so you will have to find a way to make the browser generate CRLF for you.

    One way would be to:

    • use Firefox
    • install extension TamperData
    • use it to modify the text you send, e.g. inserting %0D%0A at the beginning; which is the URL-encoded version of
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺