RE: [PHP] HTML as array elements
| From: | Christensen, BruceX R | Date: | Mon, 07 Aug 2000 23:54:45 +0000 |
| Subject: | RE: [PHP] HTML as array elements | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-10553@lists.php.net to get a copy of this message | ||
Seems to work fine for me, although you do need to add a ; after the very
last parenthesis.
Also, I'm not sure if you really want to output the echo statements, or to
execute them. If you want to execute them, you'll need to get rid of all of
the double quotes inside of the echo statements (or escape them), and then
do an eval() on the code. For example:
$db_field_list = array(
"0" => array(
"Prize" => "textbox",
"Question" => "textbox",
"snippet" => 'echo "<p><span
class=\"mpstext\"><b>This month\'s prize
is:</b></span>\n";'
)
);
eval ($db_field_list[0]["snippet"]);
will display:
<p><span class="mpstext"><b>This month's prize
is:</b></span>
Whereas this:
$db_field_list = array("0" => array(
"Prize" => "textbox",
"Question" => "textbox",
"snippet" => addslashes(
'echo "<p><span class="mpstext"><b>This
month\'s prize
is:</b></span>\n";'
)
);
echo $db_field_list[0]["snippet"];
will display:
echo \"<p><span class=\"mpstext\"><b>This month\'s prize
is:</b></span>\\n\";
--Bruce
Bruce Christensen
Intel Corporation
brucex.r.christensen@intel.com
-----Original Message-----
From: Jason Bryner [mailto:jason@focusdesigngroup.com]
Sent: Monday, August 07, 2000 4:24 PM
To: php-general@lists.php.net
Subject: [PHP] HTML as array elements
I'm trying to put HTML/PHP into an array element using the following code
below. So that I can echo the $db_field_list[0]["snippet"] and it will
output the code. But it is not working. It doesn't output anything. What
is the problem?
$db_field_list = array(
"0" => array(
"Prize" => "textbox",
"Question" => "textbox",
"snippet" => addslashes(
'echo "<p><span class="mpstext"><b>This
month\'s prize
is:</b></span>\n";
echo "<table width="100%" border="0"
cellspacing="0"
cellpadding="3">\n";
echo "<tr bgcolor="EEEEEE">\n";
echo "<td class="mpstext">" . $news[$i]["Prize"] .
"</td>\n</tr>\n</table>\n";
echo "<p><span class="mpstext"><b>This month\'s
trivia question
is:</b></span>\n";
echo "<table width="100%" border="0"
cellspacing="0"
cellpadding="3">\n";
echo "<tr bgcolor="EEEEEE">\n";
echo "<td class="mpstext">" . $news[$i]["Question"]
.
"</td>\n</tr>\n</table>\n";'
)
),
"1" => array(
"Title" => "text",
"Date" => "text",
"Author" => "text",
"News" => "textbox",
"snippet" => addslashes(
'echo "<p><span class="mpstext"><b>This
month\'s prize
is:</b></span>\n";
echo "<table width="100%" border="0"
cellspacing="0"
cellpadding="3">\n";
echo "<tr bgcolor="EEEEEE">\n";
echo "<td class="mpstext">" . $news[$i]["Prize"]
.
"</td>\n</tr>\n</table>\n";
echo "<p><span class="mpstext"><b>This month\'s
trivia
question is:</b></span>\n";
echo "<table width="100%" border="0"
cellspacing="0"
cellpadding="3">\n";
echo "<tr bgcolor="EEEEEE">\n";
echo "<td class="mpstext">" .
$news[$i]["Question"] .
"</td>\n</tr>\n</table>\n";'
)
)
)
?>
Jason
--
Focus Design
423 238 3320
http://www.focusdesigngroup.com/