0

What I have :
I have a software dump data like exactly below file :

DMPDATA = {
    ["invent1"] = {
        ["1000:1"] = {
            ["I"] = "6948",
            ["C"] = 1,
            ["G2"] = "0",
            ["G3"] = "0",
            ["G1"] = "0",
        },
        ["0000:10"] = {
            ["I"] = "39622",
            ["C"] = 1,
            ["G2"] = "0",
            ["G3"] = "0",
            ["G1"] = "0",
        },
    },
    ["invent2"] = {
        ["M:1"] = 60116,
        ["M:3"] = 32246,
        ["M:2"] = 41252,
    },
    ["invent3"] = {
        ["47465"] = 5,
        ["12970"] = 5,
    },
    ["invent4"] = {
        {
            ["F"] = 0,
            ["V"] = 0,
            ["N"] = "Classic",
        }, -- [1]
        {
            ["F"] = 16,
            ["V"] = 3500,
            ["N"] = "Horde",
        }, -- [2]
    },
    ["invent6"] = {
        ["class"] = "WARRIOR",
        ["gender"] = 2,
    },
}

Question:
I want to parse above data as array , I try to do but don't know whats better way .
How can parse files like above code with PHP to have a all data as Array ?

Root
  • 2,269
  • 5
  • 29
  • 58
  • Have you tried anything yet? A couple of `preg_replace` calls could quite easily turn this into a JSON string. Of course, it's easier if you could edit the code that is actually dumping this – Elias Van Ootegem Aug 08 '13 at 12:11
  • Thanks @EliasVanOotegem , Original files are bigger than this and I have problem to parse all it as array . – Root Aug 08 '13 at 12:16

1 Answers1

1

This looks like LUA code. Have you tried the Lua class in PHP?

http://www.php.net/manual/en/lua.eval.php

Here's a guy that has a similar problem with a WoW Addon Lua file:

I need a tool to parse Lua tables, preferrably in Ruby or Java

EDIT:

Try this tool. It also links to a PHP script you might use. http://fin.instinct.org/lua/

EDIT 2:

This is basically what you need. As you can see you're not the first person who wants to parse WoW Lua dumps to PHP arrays =)

http://fin.instinct.org/lua/lua2phparray.phps

Community
  • 1
  • 1
silkfire
  • 24,585
  • 15
  • 82
  • 105