0

I realize that in a URL, the + symbol represents a space, however I need to keep the plus sign. How can I do this? My URL and code are as follows:

http://www.example.com/path/test.php?test=2+2
<?php
    $test = $_GET['test'];

    echo $test;
?>

This prints out 2 2.

1
  • There must be a better (canonical) duplicate. That one is for ASP.NET and the answers are specific for .NET. It is mostly about the how in .NET, and it has very few details about the encoding. Nov 27, 2022 at 21:58

1 Answer 1

7

+ is interpreted as a space in a URL. To use a + you need %2B.

http://example.com/path/test.php?test=2%2B2

1
  • Technically correct, but also very narrow. Usually for a particular framework (this is tagged with PHP) there is a standard function to do it (which also covers more than this single character, +). Nov 27, 2022 at 22:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.