Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing get parameter from javascript to php destroys formatting

Tags:

javascript

php

I format text with javascript asigning + to every emtpy space like this

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

Then I pass ft to a php script via jquery ajax as an get argument.

But

print $_GET['text'];

gives me the text with empty spaces instead +.

Any ideas?

like image 631
UpCat Avatar asked Apr 08 '26 01:04

UpCat


1 Answers

You should get familiar with the concept of URL encoding.

PHP's urldecode function will run against all $_GET variables by default, so if you want to see raw input, use rawurldecode:

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

echo $encoded['text']; //blah+blah
like image 165
Jacob Relkin Avatar answered Apr 10 '26 15:04

Jacob Relkin