SimpleXML Export" SimpleXMLElement :: __ set_state(array(" in Variable

时间:2016-11-11 19:47:14

标签: php simplexml

我试图从xml文件中获取变量并将其保存为php文件

     $xmlresponse = simplexml_load_string($dom->saveXML());
   $shipmentid = $xmlresponse->ListInboundShipmentsResult->ShipmentData->member->ShipmentId;
 echo '<br />' . $shipmentid . '<br />';


 $todaydt = new DateTime('today');
 $today3 = $todaydt->format('m-d-Y') . PHP_EOL;
 $today = rtrim($today3);
$var_str = var_export($shipmentid, true);
$var = "<?php\n\n\$shipmentid = $var_str;\n\n?>";
file_put_contents('shipmentid_' . $today . '.php', $var);

 }

但是在我的shipmentid_11-11-2016.php文件中,它正在给我

  

$ shipmentid = SimpleXMLElement :: __ set_state(array(      0 =&gt; &#39; shipmentid&#39 ;,      ));

如何保存变量,只需

即可
  

$ shipmentid =&#39; shipmentid&#39;;

1 个答案:

答案 0 :(得分:1)

当你这样做时

 SELECT 'ASDF' c1, MAX (SUM (1)) c2
    FROM DUAL where 'ASDF' <> 'ASDF'
GROUP BY dummy

php隐式地将echo '<br />' . $shipmentid . '<br />'; 值转换为字符串。 $shipmentid没有这样做,所以你需要自己转换它:

var_export

接下来的事情是$var_str = strval($shipmentid); 是一个字符串,并且不包含任何引号。所以,你需要自己写引号:

$var_str