加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 23:58:39 所属栏目:百科 来源:网络整理
导读:参见英文答案 Forcing a SimpleXML Object to a string,regardless of context10个 大家好我有一个在codeigniter开发的网站. 我正在解析从服务器检索的xml,我想将返回值放入会话变量中. 但是给我这个错误: Fatal error: Uncaught exception ‘Exception’ w
参见英文答案 > 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);      
 }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读