duai4512 2010-10-21 14:17
浏览 100
已采纳

使用PHP检索textarea内容。 获得添加的反斜杠

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:
" + 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

  • 写回答

1条回答 默认 最新

  • du8589840 2010-10-21 14:28
    关注

    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!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题