views:

52

answers:

3

please help me, my problem is:

in one .txt file i have

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,
}

who is the form of convert or parse in array in php? for you help thx

A: 

you will have to read each line and interpret and construct the array manually!

deepsat
A: 

How did it get stored like that? It looks like you have sent the output of a print_r call to a file. If possible you should use the serialize command to store your array to the file: http://php.net/manual/en/function.serialize.php and then you can later unserialze the contents: http://www.php.net/manual/en/function.unserialize.php

More info: http://www.php.net/manual/en/language.oop5.serialization.php

Gerry
A: 

Assuming you will never allow other people to inject new code into this file, you can do the following to turn it into a regular PHP array and pass it trough 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);

It's a very good idea for you to scrap this and write the array back out in a serialized form instead.

meagar