By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,639 Members | 2,262 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,639 IT Pros & Developers. It's quick & easy.

Writing to Heredoc from Text Area Form

P: n/a
I can't seem to get heredoc to populate correctly with variables through
a form.

<textarea name="Template" rows="10" cols="80">Template Here</textarea>

Contents could be something like: I want to replace $myarray[0] and
another variable $myarray[1]

I call heredoc this way:

$hubarray = explode("\n", $contents);
$template = $_POST['Template'];

foreach ($hubarray as $val) {
$hostarray = explode(",", $val);

$output = <<<EOT
$template
EOT;

I'm feeding it a file that has multiple rows separated by \n as array 1
and within those rows are fields separated by "," for array 2. I'm
trying to iterate through the arrays and populate heredoc($template)
accordingly.
May 31 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
At Thu, 31 May 2007 09:45:02 -0500, Matt F let h(is|er) monkeys type:
I can't seem to get heredoc to populate correctly with variables through
a form.

<textarea name="Template" rows="10" cols="80">Template Here</textarea>

Contents could be something like: I want to replace $myarray[0] and
another variable $myarray[1]

I call heredoc this way:

$hubarray = explode("\n", $contents);
$template = $_POST['Template'];

foreach ($hubarray as $val) {
$hostarray = explode(",", $val);

$output = <<<EOT
$template
EOT;

I'm feeding it a file that has multiple rows separated by \n as array 1
and within those rows are fields separated by "," for array 2. I'm
trying to iterate through the arrays and populate heredoc($template)
accordingly.
I don't understand what $template is supposed to contain. Can you give an
example of what it might look like and what you want to do with it?

And I am missing a }. should that be following the $hostarray assignment?
In that case you probably mean $hostarray[] = explode(",", $val);

This would leave you with $hostarray looking like:
$hostarray[0][0]: <row 0, field 0>
$hostarray[0][n]: <row 0, field n>
....
$hostarray[m][0]: <row m, field 0>
$hostarray[m][n]: <row m, field n>

Maybe it would be easier (not sure how your file was populated to begin
with) to serialize the arrays, write those to a file, read them in this
script and unserialize them again.
--
Schraalhans Keukenmeester - sc*********@the.spamtrapexample.nl
[Remove the lowercase part of Spamtrap to send me a message]

"strcmp('apples','oranges') < 0"

May 31 '07 #2

P: n/a
On Thu, 31 May 2007 17:22:49 +0200, Schraalhans Keukenmeester <Sc*********@the.spamtrapexample.nlwrote:
:
: I don't understand what $template is supposed to contain. Can you give an
: example of what it might look like and what you want to do with it?
:

Here's an example:
$output = <<<EOT
set route $hostarray[0] gateway $hostarray[3]
set route $hostarray[1] gateway $hostarray[3]
set route $hostarray[2] gateway $hostarray[3]
EOT;

So I would like "set route...." placed into $template. This way,
someone else can upload a new template such as:

set policy $hostarray[0] allow $hostarray[3]
set policy $hostarray[1] allow $hostarray[3]
set policy $hostarray[2] allow $hostarray[3]
: And I am missing a }. should that be following the $hostarray assignment?
: In that case you probably mean $hostarray[] = explode(",", $val);
:

foreach ($hubarray as $val) {
$val = trim($val);
$hostarray = explode(",", $val);

$output = <<<EOT
$template
EOT;

print "$output";

}
: Maybe it would be easier (not sure how your file was populated to begin
: with) to serialize the arrays, write those to a file, read them in this
: script and unserialize them again.
:

I'm open to alternatives. I basically need some way of feeding a
variables file into a template. I've been experimenting with two file
inputs instead of heredoc using text area.

Thanks again!
Matt
May 31 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.