Why does _GET in PHP wrongly decodes slash?

Posted by Boaz on Stack Overflow See other posts from Stack Overflow or by Boaz
Published on 2010-03-15T15:36:04Z Indexed on 2010/03/15 15:39 UTC
Read the original article Hit count: 249

Filed under:
|
|

Hi,

Today I run into some oddity with PHP, which I fail find a proper explanation for in the documentation. Consider the following code:

<?php
echo $_GET['t']. PHP_EOL;
?>

The code is simple - it takes a single t parameter on the url and outputs it back. So if you call it with test.php?t=%5Ca (%5c is a '\'), I expected to see:

\a

However, this is what I got:

$ curl http://localhost/~boaz/test.php?t=%5Ca
\\a

Notice the double slash. Can anyone explains what's going on and give recipe for retrieving the strings as it was supplied on the URL?

Thanks, Boaz

© Stack Overflow or respective owner

Related posts about php

Related posts about string-escaping