-1

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

3 Answers 3

0

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.