Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php URL decode get '+' from URL

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;
?>
like image 650
Ed R Avatar asked Mar 31 '11 06:03

Ed R


People also ask

How to decode a URL in PHP?

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.

Does PHP automatically decode URL?

Yes, all the parameters you access via $_GET and $_POST are decoded.

What is Rawurldecode?

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.


1 Answers

Try using the function rawurldecode() instead of urldecode()

like image 77
Maurice Avatar answered Oct 20 '22 17:10

Maurice