douzaoqu4447 2012-01-19 22:34
浏览 728
已采纳

使用$ _GET字符串传递换行符

I have to pass a string to a form. I want to use a mix of $_GET and $_POST in the following way:

 <?php $string="bla bla bla".$some_other_string."bla bla".$some_other_string2."
"; ?>

 <form action="this_page.php?string=<?php echo $string?>" method="post" name="name">

 </form>

Please note the in the string. When I get the $_GET("string") (or $_REQUEST("string"), it happens the following: the php parser get the as a string. So he put it into the string as I had coded: \\ and it's not the result I want. I want simply a inner in a php string.

Please can you explain me why this behaviour happens, without complaining that it's not the best way to pass a string (I suppose it isn't, but today I had an issue and I wanted to manage it by passing the string this way)?

Ps: I have to use the and not the html <br /> because I have to let php write into a file.

  • 写回答

1条回答 默认 最新

  • douluan4644 2012-01-19 22:39
    关注

    Advice: You probably should think about putting this into a hidden field

    Answer: But if you are going to put it into action as a GET parameter, then you need to urlencode the string:

    <form action="this_page.php?string=<?php echo urlencode($string); ?>" method="post" name="name">
    

    That way - any non-alphanumeric characters will be url safe (think about what might happen if $string contained a ? or a # or an = ).

    PHP automatically decodes GET parameters when loading them into the $_GET array - so your newline should be preserved at that point.

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

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?