views:

37

answers:

1

I am building a web application that is supposed to make it easier for users to generate correct XML for a given utility.

As a simple test, I created a textarea that contains the generated XML. I then created a button (<input type="button">) with a jQuery handler that will send the contents of the text area to my PHP application, which will massage the data and place the various items into a . The code I am using the send the data to PHP is as follows (assume 'this' is a complex object, and doImport() is a function within that object... this is working properly):

doImport :  function () {
  var $ = this.jQuery,
   js = this,
   xml = $('textarea#xmlInput').val();

  $.post(this.selfRef, {
   import : xml
  }, function (json) {
   if (json.status) {
    $('table#tableArea tbody').html(json.tableInfo);
   } else {
    alert("Error occurred:\n" + json.message);
   }
  }, 'json');
 },

I can examine the data using Firebug, and I'm correctly getting the XML data from the text area. I expect my PHP application to generate a JSON result.

Next, on the PHP side, when I retrieve the POST information using $_REQUEST['import'], I'm getting the following:

<?xml version=\"1.0\"?> [...]

In other words, the double quotes are being escaped by backslashes.

I've tried examining the string character by character, and I'm indeed seeing the backslashes in the string returned by $_REQUEST['import'].

I know I am probably overlooking something extremely simple, but for the life of me, I cannot figure out what I'm doing wrong.

Regards,

lar3ry

+3  A: 

Your PHP installation has "magic_quotes" turned on. It's a "security" feature introduced long ago. (Really it just causes problems like this IMHO).

I believe you have to turn it off in the php.ini (usually found in /etc if you're using linux). Change

magic_quotes_gpc = On 

to

magic_quotes_gpc = Off

If that doesn't work you can use the stripslashes() function on your input.

$_POST['import'] = stripslashes($_POST['import']);

Hope that helps!

Cfreak
The magic quotes was the culprit. Thanks!
lar3ry