2013-03-18 21 views
4

大家好我有笨開發的網站。 我解析,我從服務器檢索XML,我想提出的返回值到一個會話變量。 但回到我這個錯誤:在我的VPS的SimpleXMLElement「的序列化'是不允許的錯誤插入的會話XML值

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

我的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);  
} 

回答

14

可能嘗試更改它之前添加字符串,如:

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);  
} 
+0

它的工程很棒!但爲什麼不是一個字符串? put(string)之前的格式是什麼? – 2013-03-18 09:57:34

+0

@AlessandroMinoccheri其資源類型和資源不能被序列化,因此錯誤.. – 2013-03-18 10:00:04

+0

感謝您的幫助,併爲解釋+1 – 2013-03-18 10:00:58

相關問題