2011-04-10 53 views
0

我正試圖在facebook中存儲Facebook用戶的數據數組。我已經使用序列化來轉換數組。當我嘗試檢索數據時,我會得到絕對的空白頁面。沒有錯誤,沒有輸出。我用下面的例子給出了我的代碼。請幫我找到錯誤。PHP unserialize()試圖存儲Facebook用戶數據時不工作

$arrayString='a:18:{s:2:"id";s:10:"7234123543";s:4:"name";s:18:"John Mc Carthy";s:10:"first_name";s:7:"John";s:11:"middle_name";s:5:"Mc";s:9:"last_name";s:4:"Carthy";s:4:"link";s:35:"http://www.facebook.com/johnmc";s:8:"username";s:11:"johnmc";s:8:"hometown";a:2:{s:2:"id";s:15:"112334563280811";s:4:"name";s:7:"Some city";}s:8:"location";a:2:{s:2:"id";s:15:"112312348780092";s:4:"name";s:16:"Some city, country";}s:6:"quotes";s:234:""All children are artists. The problem is how to remain an artist once you grow up." 
- Pablo Picasso 

"Boundaries are meant to be broken" 
- Malik raza 

"Make things as simple as possible but no simpler." 
- Albert Einstein";s:20:"inspirational_people";a:6:{i:0;a:2:{s:2:"id";s:15:"109233712349424";s:4:"name";s:10:"Bill Gates";}i:1;a:2:{s:2:"id";s:15:"108103675884224";s:4:"name";s:20:"A. P. J. Abdul Kalam";}i:2;a:2:{s:2:"id";s:15:"104389809597530";s:4:"name";s:13:"Chris Gardner";}i:3;a:2:{s:2:"id";s:11:"11777366210";s:4:"name";s:12:"Paulo Coelho";}i:4;a:2:{s:2:"id";s:11:"68310606562";s:4:"name";s:15:"Mark Zuckerberg";}i:5;a:2:{s:2:"id";s:15:"113529011990795";s:4:"name";s:10:"Steve Jobs";}}s:9:"education";a:2:{i:0;a:4:{s:6:"school";a:2:{s:2:"id";s:15:"11";s:4:"name";s:5:"college";}s:4:"year";a:2:{s:2:"id";s:15:"144044823450606";s:4:"name";s:4:"2011";}s:13:"concentration";a:1:{i:0;a:2:{s:2:"id";s:15:"192578844099494";s:4:"name";s:16:"Computer Science";}}s:4:"type";s:7:"College";}i:1;a:2:{s:6:"school";a:2:{s:2:"id";s:15:"103122365394699";s:4:"name";s:22:"My School";}s:4:"type";s:11:"High School";}}s:6:"gender";s:4:"male";s:5:"email";s:19:"[email protected]";s:8:"timezone";d:15.5;s:6:"locale";s:5:"en_US";s:8:"verified";b:1;s:12:"updated_time";s:24:"2011-04-09T21:51:29+0000";}'; 
     $array=unserialize($arrayString); 
     //echo $array[0]; 
     print_r($array); 
+0

我得到「錯誤在偏移量68 1720字節」 - 似乎序列化出了錯點。 – 2011-04-10 23:08:21

回答

1

很可能您的序列化數據格式不正確/您忘記了需要轉義的字符。爲了讓PHP給你本回閤中,錯誤報告和顯示錯誤的一些詳細的錯誤報告:

ini_set("error_reporting", E_ALL); 
ini_set("display_errors", 1); 

「通知」是不正常獲得顯示足夠重要的錯誤信息,但在這種情況下,它會幫助你調試你的序列化的問題:

Notice: unserialize(): Error at offset 68 of 1720 bytes in file.php on line 7 
+0

謝謝朋友! – hiprakhar 2011-04-11 03:37:23