-5

I am sending below data from textarea:

<?php
for ($x=0; $x<=10; $x++)
  {
  echo "The number is: $x <br>";
  }
?> 

But when I get the data from the client on server it becomes like below. It escapes the ++

sign which is special character.

<?php
for ($x=0; $x<=10; $x)
  {
  echo "The number is: $x <br>";
  }
?>

How to get data as it is sent?

brasofilo
  • 25,496
  • 15
  • 91
  • 179
Sanjay Rathod
  • 1,083
  • 5
  • 18
  • 45

2 Answers2

1

Submitting raw input with a plus sign via HTTP GET will cause the plus sign to not be sent. It is a reserved character. See here.

Your old code built the GET request by hand like so:

var code = "code=" + code;
$.ajax({
  // ...
  data: code,
  /// ...
});

But you never used encodeURIComponent(code), thus causing your plus signs to be lost to the gaping jaws of the specification.

var code = "code=" + encodeURIComponent(code);

jQuery will do this automatically though if you pass it a plain object. Building urls is annoying, so this is the pattern I prefer:

$.ajax({
  // ...
  data: {
    code: code
  },
  /// ...
});
Community
  • 1
  • 1
Jackson
  • 9,188
  • 6
  • 52
  • 77
0

With no comments on the rest of your code, you are executing a GET request.. For url encoding, a + sign is equal to a space. But if you want to retain those plus signs(+) upon the submission of the data.. you must url encode the string. There is a function for this, encodeURIComponent(str). I would suggest you use that. That aside, be careful what you evaluate php wise.

Normally, the form would take care of this for you, but since you are circumventing that action, this is one of the fixes.

Daedalus
  • 7,586
  • 5
  • 36
  • 61