duangu1878 2017-05-02 00:11
浏览 292
已采纳

php如何在POST变量中转义换行符

I have a form that allows the user to enter what character to trim from the end of a string. Here's a simple example. The form submits back to itself and alters the string Testing 123, If you enter a comma into the form, you get back Testing 123 (comma is removed). But what if that same string had a line break after the comma. I want to be able to enter , into the form and have it return Testing 123 So both the empty line and the comma are trimmed. I assume it has to be escaped, but I can't figure it out. I've tried removeslashes, htmlspecialchars, urldecode. I can't seem to get it.

<?php
if (empty($_POST['trim'])) {
echo "<form method='post' action='".$_SERVER["PHP_SELF"]."'>
<input type='text' name='trim'>
<input type='submit' value='submit'>
</form>";exit;}

$str="testing 123,
";
$str=rtrim($str,$_POST['trim']);
echo $str;
?>
  • 写回答

1条回答 默认 最新

  • doufu9836 2017-05-02 01:34
    关注
    $str = rtrim($str);
    $str = rtrim($str, $_POST['trim']);
    

    Will remove whitespace at the end of the string then whatever the user provides.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器