Greetings.

There is a GET request that stores URLs of the form: site.com/example/227172/Text+othertext

But after attempting to receive this GET request, the URL is converted to this form: site.com/example/227172/Text othertext. That is, somewhere the "+" sign drops, how can I fix this?

  • [ urlencode() ] [1] [1]: php.net/manual/ru/function.urlencode.php - Johny
  • @Johny, tried, it turns out generally porridge:% 2Fexample% 2F203172% 2FText + othertext - evansive
  • And, well, if the plus remains here, then rawurlencode() Before receiving, you will make rawurldecode() - Johny
  • Simply the "+" sign replaces the space when encoding. - Johny
  • @Johny, did this: $ get = rawurlencode ($ _ GET ['id']); It turns out like this:% 2Fexample% 2F175132829% 2Ftext% 20othertext Accordingly, the page is not parsed; ( - evansive

1 answer 1

GET parameters are processed by urldecode (). Urldecode () decodes any% ## encoded sequences in this string. The plus ('+') character is decoded into a space character.

If you try to get site.com/example/227172/Text% 2B othertext, you will end up with site.com/example/227172/Text+othertext

Here is one solution to the problem:

 $string = $_GET['str'] $string = urlencode($string); $string = str_replace("+", "%2B",$string); $string = urldecode($string); 

And second:

 $string = $_GET['str'] $string = urlencode($string); $string = rawurldecode($string); 
  • Your answer will not work as it is, because the + sign must be processed before sending the GET request, and not after. Instead of the + character, a space is already coming to the server. index.php? name = test +++ end, we get the test end. - iSavaDevRU