Defining an array with an array of keys and a variable name.
Posted: Wed Mar 09, 2005 8:31 pm
As of now, I have this code.
What I have is an array "$iterate" that defines the key for a variable I'm making. In simple PHP terms, this would be:
The problem is the "..." I have an arbitrary nesting scheme (the depth of the array varies), and thus I can't use a construct like that to define my array through keys. And thus I've been forced to use eval().
I have a few questions:
1. Is using eval() in this case evil? Is eval() evil in most cases?
2. Am I doing something wrong when I'm organizing my data this way? Should I just start using databases? How do you suggest I store data if I need to make direct changes to the database and them upload them to the site?
3. If this is the correct way of doing it (or semicorrect, for that matter), IS THERE A BETTER WAY?
Thanks. A minor note: Here's a sample of what this might parse:
Creating the corresponding variables into the global space. There are three variables that are operated on: $sinf, $sc and $authinfo (which isn't displayed)
feyd | hey look ma,
Code: Select all
if (checkvarname($iterate[0])) {
$code = "\${$iterate[0]}";
array_shift($iterate);
foreach ($iterate as $readfile_value) {
if ($readfile_value == "") {
$code .= "[]";
} else {
$code .= "['$readfile_value']";
}
}
$code .= " = \$data;";
eval($code);
}Code: Select all
${$iterateї0]}ї$iterateї1]]ї$iterateї2]]ї$iterateї3]]... = $data;I have a few questions:
1. Is using eval() in this case evil? Is eval() evil in most cases?
2. Am I doing something wrong when I'm organizing my data this way? Should I just start using databases? How do you suggest I store data if I need to make direct changes to the database and them upload them to the site?
3. If this is the correct way of doing it (or semicorrect, for that matter), IS THERE A BETTER WAY?
Thanks. A minor note: Here's a sample of what this might parse:
Code: Select all
$sinf:supercategory:cage>original
$sinf:maincategory:cage>fiction
$sinf:creation:cage>2005.02.13
$sinf:update:cage>2005.02.13
$sinf:sc:s:cage>chtml
$sinf:injectstyle:cage:lyrics>font-style:italic;
$sinf:sc:t:cage>> "e;їїї"e; => "e;font-family:'Monotype
Corsiva',cursive,serif;font-size:16pt;text-align:center;"e;,
"e;==="e; => "e;font-style:italic;text-align:center;"e;
$sc:n:cage:1>Prologuefeyd | hey look ma,
Code: Select all
is online. [/color]