doulu7258 2014-04-18 04:01
浏览 52
已采纳

Href中的PHP Echo切断变量

In my form action:

    <form class="login" style=" ;"method="post" action=<?php echo "add_answer.php?id="; echo $id; echo "&z=$zipcode&d=$date&category=$category"; ?>">

$category is a 2 word variable "lawn mowing". However, it directs me to the link:

add_answer.php?id=1&z=55901&d=04/25/2014&category=Lawn

If you notice the end is "Lawn" instead of "Lawn Mowing" I made sure $category is "Lawn Mowing" as it is displayed in a header on the page. How can I fix this so the whole word is passed through the URL?

  • 写回答

3条回答 默认 最新

  • dqvtm82066 2014-04-18 04:05
    关注

    You need to urlencode() the variables.

    <form class="login" style=" ;"method="post" action=<?php echo "add_answer.php?id=".urlencode($id)."&z=".urlencode($zipcode)."&d=".urlencode($date)."&category=".urlencode($category); ?>">
    

    Why do I have to urlencode() ?

    A URI is always in an "escaped" form, since escaping or unescaping a completed URI might change its semantics. Normally, the only time escape encodings can safely be made is when the URI is being created from its component parts; each component may have its own set of characters that are reserved, so only the mechanism responsible for generating or interpreting that component can determine whether or not escaping a character will change its semantics. Likewise, a URI must be separated into its components before the escaped characters within those components can be safely decoded.

    In some cases, data that could be represented by an unreserved character may appear escaped; for example, some of the unreserved "mark" characters are automatically escaped by some systems. If the given URI scheme defines a canonicalization algorithm, then unreserved characters may be unescaped according to that algorithm. For example, "%7e" is sometimes used instead of "~" in an http URL path, but the two are equivalent for an http URL.

    Because the percent "%" character always has the reserved purpose of being the escape indicator, it must be escaped as "%25" in order to be used as data within a URI. Implementers should be careful not to escape or unescape the same string more than once, since unescaping an already unescaped string might lead to misinterpreting a percent data character as another escaped character, or vice versa in the case of escaping an already escaped string.

    Source

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog