'SimpleXMLElement' 的序列化不允许在会话 xml 值中插入错误 [英] 'Serialization of 'SimpleXMLElement' is not allowed Error insert in session xml value
本文介绍了'SimpleXMLElement' 的序列化不允许在会话 xml 值中插入错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,我有一个用 codeigniter 开发的网站.我正在解析从服务器检索的 xml,我想将返回值放入会话变量中.但是返回给我这个错误:
Hi all I have a site developed in codeigniter. I'm parsing an xml that I retrieve from a server and I want to put the return value into a session variable. But return me this error:
致命错误:未捕获的异常 'Exception' 带有消息 'SimpleXMLElement' 的序列化是不允许的
Fatal error: Uncaught exception 'Exception' with message 'Serialization of 'SimpleXMLElement' is not allowed
我的 vps 上的 PHP 版本是:PHP 版本 5.3.10-1ubuntu3.4
My PHP version on my vps is: PHP Version 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);
}
推荐答案
可以尝试在添加之前将其更改为字符串,例如:
may be try changing it to string before adding, like:
foreach ($xml->DATA as $entry){
$code_travco = (string) $entry->attributes()->COUNTRY_CODE;
$name_en = (string) $entry->COUNTRY_NAME;
$newdata = array(
'code' => $code_travco,
'name_en' => $name_en
);
$this->session->set_userdata($code_travco.'_nation_en', $newdata);
}
这篇关于'SimpleXMLElement' 的序列化不允许在会话 xml 值中插入错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文