dpp66953 2014-04-16 16:02
浏览 49
已采纳

从$ _POST数组加载XML字符串

I receive a $_POST array from a system after a certain action has been performed on a database. I've tried accesing the array and saving it as an simple_xml object. So far I have not succeeded. The array which is being sent looks like this.

Array
(
     [xml] => <?xml version=\"1.0\"?>
     <callback><profile><id>313009</id><fields><email>tomkriek@gmail.com</email><nieuwsbrief>8</nieuwsbrief></fields><interests></interests></profile><action>update</action><parameters><nieuwsbrief>8</nieuwsbrief></parameters></callback>
)

I've tried storing this as a simple_xml object like this.

if($xml_test = simplexml_load_string($_POST['xml']))
{
    $xml_test->saveXML('test.xml');
}

I can save a different kind of .xml file so I'm sure the permissions are set right. As for the rest I'm not that familiar with formatting and parsing .xml files so I hope anyone could help a hand with this.

My desired outcome is that I can access the newly made simple_xml object and access the values and fields.

  • 写回答

2条回答 默认 最新

  • dongmei2351 2014-04-16 16:11
    关注

    Need to stripslashes():

    $string = stripslashes($_POST['xml']);
    
    if($xml_test = simplexml_load_string($string))
    {
        $xml_test->saveXML('test.xml');
    }
    

    It would be better to turn off magic_quotes_gpc in php.ini:

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 关于#目标检测#的问题:(qq收集表到时间才能填写,填写的份数有上限)
  • ¥50 ZYNQ7020双核FLAHS烧写的问题
  • ¥20 ue 5 中想要实现第一人称人物左右行走摆动的效果,摄像头只向右摆动一次(关键词-结点)
  • ¥15 钢岔管添加弹性约束模拟围岩作用
  • ¥15 AD9164瞬时带宽1.8G,怎么计算出来?
  • ¥15 鼠标右键,撤销删除 复制 移动,要怎样删除
  • ¥15 使用MATLAB进行余弦相似度计算加速
  • ¥15 服务器安装php5.6版本
  • ¥15 我想用51单片机和数码管做一个从0开始的计数表 我写了一串代码 但是放到单片机里面数码管只闪烁一下然后熄灭
  • ¥20 系统工程中,状态空间模型中状态方程的应用。请猛男来完整讲一下下面所有问题