This code:
$query = array(
"var" => "no",
"not_var" => "yes",
"var2" => "maybe"
);
print http_build_query($query);
Outputs:
var=no¬_var=yes&var2=maybe
This happens on my own machine running PHP 5.3.19. I've reproduced this behavior on PHPfiddle. It works as expected on ideone.com running PHP 5.2.11.
Why does this happen?
This is only because of your browser encoding the ¬
entity, try this:
print htmlentities(http_build_query($query));
For normal usage, it will be absolutely fine.
The reason it's different on ideone
vs PHPFiddle
is because PHPFiddle
just dumps the results into an iframe, and ideone
is displaying it pre-entity encoded so that other displays aren't broken.
Have you done a "view source" on the result, or are you relying on the browser to show it?
In fact, it is outputting the string as expected; it is the browser that is interpreting it incorrectly.
The string contains ¬
. This is being interpreted by the browser as an HTML entity, despite the fact that it is missing the trailing semicolon.
If you view source, you'll see that the output is actually correct.
Solution: If you want this string to be included in an HTML page, you should htmlencode it as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With