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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
John55
  • 301
  • 2
  • 11
  • 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. – Peter Mortensen Nov 27 '22 at 21:58

1 Answers1

7

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

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Brian Riley
  • 926
  • 1
  • 7
  • 12
  • 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, `+`). – Peter Mortensen Nov 27 '22 at 22:01