Passing get parameter from javascript to php destroys formatting

I am formatting text with javascript asigning +for each emtpy space like this

var ft = text.replace(/ /g,"+");

Then I pass the ftscript to PHP via jquery ajax as the get argument.

But

print $_GET['text'];

gives me text with empty space instead of +.

Any ideas?

+3
source share
2 answers

You should familiarize yourself with the concept of URL encoding .

The PHP urldecodefunction will work with all variables $_GETby default, so if you want to see the original input, use rawurldecode:

$encoded = array_map('rawurldecode', $_GET);

echo $encoded['text']; //blah+blah
+2
source

, JSON javascript PHP.

0

Source: https://habr.com/ru/post/1795453/


All Articles