2010-10-29 51 views
-1

請幫幫我,我的問題是:在解析文件到PHP數組

一個txt文件

我有

rpgoCPpref = { 
["enabled"] = true, 
["button"] = true, 
["debug"] = false, 
["questsfull"] = false, 
["tooltipshtml"] = true, 
["tooltip"] = true, 
["verbose"] = false, 
["scan"] = { 
    ["inventory"] = true, 
    ["talents"] = true, 
    ["glyphs"] = true, 
    ["honor"] = true, 
    ["reputation"] = true, 
    ["spells"] = true, 
    ["pet"] = true, 
    ["equipment"] = true, 
    ["currency"] = true, 
    ["companions"] = true, 
    ["professions"] = true, 
    ["mail"] = true, 
    ["skills"] = true, 
    ["quests"] = true, 
    ["bank"] = true, 
}, 
["ver"] = 30000, 
["fixicon"] = true, 
["talentsfull"] = true, 
["fixtooltip"] = true, 
["fixcolor"] = true, 
["lite"] = true, 
["reagentfull"] = true, 
["fixquantity"] = true, 
} 

誰是轉換的形式或陣列分析在PHP?爲您提供幫助thx

回答

0

您將不得不閱讀每行並手動解釋和構造數組!

0

假設你會永遠讓其他人來注入新代碼到這個文件,你可以執行以下操作把它變成一個普通的PHP數組並把它傳遞槽eval

$str = file_get_contents($your_file); 

$str = preg_replace('/(["\w]+) = {/', '$\1 = array(', $str); 
$str = preg_replace('/\[(["\w]+)\] = {/', '\1 => array(', $str); 
$str = preg_replace('/\[(["\w]+)\] = (.+),/', '\1 => \2,', $str); 
$str = preg_replace('/}/', ')', $str); 

eval($str); 

var_dump($rpgoCPpref); 

這是一個非常好的主意,你放棄這和數組寫回代替serialized表單。