2010-10-29 50 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表单。