So I am trying to encode/decode a url that when decoded will return the encoded +
symbols from teh url. For example, I encodewebsite.com/index.php?eq=1+12
which when encoded turns the +
into %2B
, as it should. When I retrieve the value from $_REQUEST['eq']
and use urldecode()
it echo's as "1 12"
. I cannot seem to get the decode to bring back the +
so to speak. Am I doing something wrong here, or is there a more efficient/better way to go about doing this? Here is the exact encode/decode lines I use.
Submit Page
<?php
$eq = "1+12";
$send = '<a href="website.com/index.php?eq='.urlencode($eq).'</a>';
echo $send;
Retrieval page
<?php
$eq = urldecode($_REQUEST['eq']);
echo $eq;
?>
PHP | urldecode() Function The urldecode() function is an inbuilt function in PHP which is used to decode url which is encoded by encoded() function. Parameters: This function accepts single parameter $input which holds the url to be decoded. Return Value: This function returns the decoded string on success.
Yes, all the parameters you access via $_GET and $_POST are decoded.
Description ¶ rawurldecode(string $string ): string. Returns a string in which the sequences with percent ( % ) signs followed by two hex digits have been replaced with literal characters.
Try using the function rawurldecode()
instead of urldecode()
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