微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

‘不允许序列化’SimpleXMLElement’错误插入会话xml值

参见英文答案 > Forcing a SimpleXML Object to a string,regardless of context10个
大家好我有一个在codeigniter开发的网站.
我正在解析从服务器检索的xml,我想将返回值放入会话变量中.
但是给我这个错误

Fatal error: Uncaught exception ‘Exception’ with message ‘Serialization of ‘SimpleXMLElement’ is not allowed

我的vps上的PHP版本是:
PHP版本5.3.10-1ubuntu3.4

这是我的代码

$xml = new SimpleXMLElement(curl_exec($ch2));
$error2=curl_getinfo( $ch2,CURLINFO_HTTP_CODE );
curl_close($ch2);
foreach ($xml->DATA as $entry){
    $code_travco = $entry->attributes()->COUNTRY_CODE;
    $name_en =  $entry->COUNTRY_NAME;
    $newdata = array(
        'code'  => $code_travco,'name_en'     =>  $name_en
    );
    $this->session->set_userdata($code_travco.'_nation_en',$newdata);      
 }
可能会尝试在添加之前将其更改为字符串,例如:
foreach ($xml->DATA as $entry){
    $code_travco = (string) $entry->attributes()->COUNTRY_CODE;
    $name_en =  (string) $entry->COUNTRY_NAME;
    $newdata = array(
        'code'  => $code_travco,$newdata);      
 }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。