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 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥85 maple软件,solve求反函数,出现rootof怎么办?
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题