I have a url like
test.php?x=hello+world&y=%00h%00e%00l%00l%00o
when i write it to file
file_put_contents('x.txt', $_GET['x']); // -->hello world
file_put_contents('y.txt', $_GET['y']); // -->\0h\0e\0l\0l\0o
but i need to write it to without encoding
file_put_contents('x.txt', ????); // -->hello+world
file_put_contents('y.txt', ????); // -->%00h%00e%00l%00l%00o
how can i do?
Thanks
i think you can use
urlencode()
to pass the value in URL andurldecode()
to get the value.You can get unencoded values from the $_SERVER["QUERY_STRING"] variable.
Because the The
$_GET
and$_REQUEST
superglobals are automatically run through a decoding function (equivalent tourldecode()
), you simply need to re-urlencode()
the data to get it to match the characters passed in the URL string:I've tested this out locally and it's working perfectly. However, from your comments, you might want to look at your encoding settings as well. If the result of
urlencode($_GET['y'])
is%5C0h%5C0e%5C0l%5C0l%5C0o
then it appears that thenull character
that you're passing in (%00
) is being interpreted as a literal string"\0"
(like a\
character concatenated to a0
character) instead of correctly interpreting the\0
as a single null character.You should have a look at the PHP documentation on string encoding and ASCII device control characters.