
July 17th, 2005, 10:59 AM
| | | Creating a variable from a text file
Heya,
I have a text file which is basically an array declaration and I would
like to assign this to a array variable.
It reads like this (extract)
myProfile = {
["Blackhand"] = {
["Fingali"] = {
["Inventory"] = {
["Bag4"] = {
["Contents"] = {
[1] = {
["Quantity"] = 1,
["Name"] = "Hearthstone",
["Color"] = "ffffffff",
["Tooltip"] = {
[1] = "Hearthstone",
[2] = "Soulbound",
[3] = "Unique",
[4] = "Use: Returns you to The Crossroads. Speak to an
Innkeeper in a different place to change your home location.",
},
["Item"] = "6948:0:0:0",
["Texture"] = "Interface\\Icons\\INV_Misc_Rune_01",
},
[2] = {
["Quantity"] = 1,
["Name"] = "Skinning Knife",
["Color"] = "ffffffff",
["Tooltip"] = {
[1] = "Skinning Knife",
[2] = "One-Hand",
[3] = "2 - 5 Damage",
[4] = "(2.2 damage per second)",
},
["Item"] = "7005:0:0:0",
["Texture"] = "Interface\\Icons\\INV_Weapon_ShortBlade_01",
},
[3] = {
["Quantity"] = 7,
["Name"] = "Cactus Apple Surprise",
["Color"] = "ffffffff",
["Tooltip"] = {
[1] = "Cactus Apple Surprise",
[2] = "Use: Restores 61 health over 18 sec. Must remain seated
while eating. If you spend at least 10 seconds eating you will become
well fed and gain 2 Stamina and Spirit for 15 min.",
},
["Item"] = "11584:0:0:1388764288",
["Texture"] = "Interface\\Icons\\INV_Misc_Food_19",
.....
I tried this
$lua = urldecode($lua);
$thefile = implode("", file($lua));
$arr = ${$thefile};
But it doesn't work. Any ideas ? | 
July 17th, 2005, 10:59 AM
| | | Re: Creating a variable from a text file
Your field definition is already there.
Why don't you just get rid of this: "myProfile = " , then do whatever
other adjustments you need to the text (if any)
and then assign the resulting string to your variable? | 
July 17th, 2005, 11:00 AM
| | | Re: Creating a variable from a text file
"skarr" <koen.willocx@telenet.be> wrote in message
news:1102933570.420639.270590@c13g2000cwb.googlegr oups.com...[color=blue]
> Heya,
>
> I have a text file which is basically an array declaration and I would
> like to assign this to a array variable.
>
> It reads like this (extract)
>
> myProfile = {
> ["Blackhand"] = {
> ["Fingali"] = {
> ["Inventory"] = {
> ["Bag4"] = {
> ["Contents"] = {
> [1] = {
> ["Quantity"] = 1,
> ["Name"] = "Hearthstone",
> ["Color"] = "ffffffff",
> ["Tooltip"] = {
> [1] = "Hearthstone",
> [2] = "Soulbound",
> [3] = "Unique",
> [4] = "Use: Returns you to The Crossroads. Speak to an
> Innkeeper in a different place to change your home location.",
> },
> ["Item"] = "6948:0:0:0",
> ["Texture"] = "Interface\\Icons\\INV_Misc_Rune_01",
> },
> [2] = {
> ["Quantity"] = 1,
> ["Name"] = "Skinning Knife",
> ["Color"] = "ffffffff",
> ["Tooltip"] = {
> [1] = "Skinning Knife",
> [2] = "One-Hand",
> [3] = "2 - 5 Damage",
> [4] = "(2.2 damage per second)",
> },
> ["Item"] = "7005:0:0:0",
> ["Texture"] = "Interface\\Icons\\INV_Weapon_ShortBlade_01",
> },
> [3] = {
> ["Quantity"] = 7,
> ["Name"] = "Cactus Apple Surprise",
> ["Color"] = "ffffffff",
> ["Tooltip"] = {
> [1] = "Cactus Apple Surprise",
> [2] = "Use: Restores 61 health over 18 sec. Must remain seated
> while eating. If you spend at least 10 seconds eating you will become
> well fed and gain 2 Stamina and Spirit for 15 min.",
> },
> ["Item"] = "11584:0:0:1388764288",
> ["Texture"] = "Interface\\Icons\\INV_Misc_Food_19",
> ....
>
>
> I tried this
>
> $lua = urldecode($lua);
> $thefile = implode("", file($lua));
> $arr = ${$thefile};
>
> But it doesn't work. Any ideas ?
>[/color]
Try this:
$code = '$' . strtr($data, array(
'{' => 'array(',
'}' => ')',
'=' => '=>',
'[' => '',
']' => ''
));
eval($code);
Couldn't test this since the data you provided is truncated. |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | | What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over network members.
|