4

I have a form like this to send a utf-8 string parameter.

<form rel="search" action="/archives" method="get">

 <input name="key" type="text" value="تست" />

 <input type="submit" value="submit"  />

</form>

But the url changes to

http://localhost/archives?key=%26%231578%3B%26%231587%3B%26%231578%3B

and value of this parameters in destination is wrong: *3*

Is there a way to avoide encode in url like this: http://localhost/archives?key=تست

because if I enter http://localhost/archives?key=تست in my browser,value of this parameters in destination is true...also encode stirng is ugly in the url

user3307827
  • 556
  • 1
  • 7
  • 20

3 Answers3

1

The URL change you are seeing is perfectly normal: The browser needs to URL encode the request to create a valid URL query string. PHP automatically URL decodes all $_GET parameters so you don't need to care about this.

First of all: is the charset of your html correctly set to utf-8?

http://www.w3.org/International/O-charset

html5:

<meta charset="utf-8"> 

other html:

<meta http-equiv="Content-Type" content="text/html;charset=utf-8">

on xhtml too:

<?xml version="1.0" encoding="utf-8" ?>

Second: is your web server serving utf-8? Is the browser establishing utf-8 encoding on the get request?

On apache, you can set the encoding on httpd.conf:

AddDefaultCharset utf-8

Also, you can set the header on PHP:

header("Content-Type: text/html;charset=UTF-8");

You can check the content-type header of served document and the get request using the network tab on developer tools (ctrl+shift+i on chrome)

Third: Check out this mbstring cheasheet to properly handle multibyte charsets in PHP

http://blog.loftdigital.com/blog/php-utf-8-cheatsheet

Also, check out this other answer:

UTF-8 not working in HTML forms

Community
  • 1
  • 1
NotGaeL
  • 8,344
  • 5
  • 40
  • 70
0

Since you are sending information to the server, why not use POST? In this case no parameters will be seen in the URL.

<form rel="search" action="/archives" method="post">

 <input name="key" type="text" value="تست" />

 <input type="submit" value="submit"  />

</form>

and you can read the parameter using

$_POST['key']
Aris
  • 4,643
  • 1
  • 41
  • 38
0

Why don't you use "post" method instead? It will completely hide your url and any kind of encoding.

Ansh
  • 94
  • 4