Tuesday, 15 May 2012

php - Character Loss converting _GET Array to URL string -


There is a very strange problem with the conversion of $ _GET request in the string. (PHP 5.2.17)

Here the problem of array from print_r is a small piece of field ():

  _GET (array) ... [address_country_code] = & gt; GB [address_name] = & gt; Super Mario [Notification] = & gt; 3.7 ...   

_GET data is used in two cases:

case 1): saved later on Done:

  // Script1.php $ data = json_encode ($ _ GET); # & Gt; Save in MySQL database ($ data) // Script2.php (URL for later viewing and checking) # & gt; Load from database ($ result) echo http_build_query (json_decoded ($ result, true));   

The result of array slice above: (right output)

address_country_code = GB & amp; ADDRESS_NAME = Super + Mario & amp; Notify_version = 3.7 case 2): used in the same script as case 1) before saving in Case 1): < Pre> // echo Script1.php http_build_query ($ _ GET);

Results in: (wrong output)

address_country_code = GB & amp; ADDRESS_NAME = Super + MarioƂ¬ify_version = 3.7

How is it possible that some characters have outputs in a 2 case, even though the case 1 is OK! It's driving me crazy: I've also tried to use a custom function instead of http_build_query that generates urlencode () in the value of the key and foreach loop, it just has to be used Changed% C2% AC in one of your test cases!

Everything If you do this with your data, then you can verify it:

  $ query = http_build_query ($ _ GET); parse_str ($ query, $   

You will get the right uncorrupted data.

And the reason is that you see the ¬ symbol How the browser is interpreted HTML entities. & Amp; not; but the browser will finally render it without semicolons. < / Html>

No comments:

Post a Comment