开发者

URL encoding in PHP

I am trying to see if URL encoding of GET parameters while submitting a form is possible. I have seen a few resources where URL encoding is being is used where the URLs are buil开发者_开发技巧t dynamically

Example: www.google.com?query=urlencode($query)

But how do I apply the function urlencode() if I am using a form and a submit button?

<html>
    <body>
        <form action="send.php" method="get">
            <input type="input" name="method" value="" />
            <input type="submit" name="submit" value="submit"/>
        </form>
    </body>
</html>


The browser will urlencode them for you. Go to google and search for "&", and you'll see "q=%26" in the URL.


This is done by the browser if you ask it to do it. Consider using enctype="application/x-www-form-urlencoded":

<html>
    <body>
        <form action="send.php" method="get" enctype="application/x-www-form-urlencoded">
            <input type="input" name="method" value="" />
            <input type="submit" name="submit" value="submit"/>
        </form>
    </body>
</html>

Note that it is done by default in most modern browsers if you don't even specify enctype.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜