473,463 Members | 1,533 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Writing to Heredoc from Text Area Form

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
2 2133
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: bigoxygen | last post by:
Is it possible to invoke a function from inside heredoc? Thanks
7
by: flupke | last post by:
Hi, i have php script where i use a heredoc type of variabele to print out some html. In the heredoc, i use the values of several other vars. php snippet: $div=<<<END_DIV <DIV...
4
by: john smith | last post by:
Hi, I have a file format that is going to contain some parts in ascii, and some parts with raw binary data. Should I open this file with ios::bin or no? For example: filename: a.bin number of...
2
by: Adam | last post by:
Greetings, I trying to but buttons for the users to write special characters to a text area in a form by clicking in a button. <form name="form1" onSubmit="return (function1() && function2()...
10
by: cj | last post by:
I'm having a problem writing an insert command to work with a datatable. I've looked at what the sqldataadapter creates and created my insert command to look the same. I have:...
10
by: Jake Barnes | last post by:
This weekend I wanted to learn AJAX, so I set up a little toy page where I could experiment. The idea of this page is that you click in one of the boxes to get some controls, at which point you can...
1
by: ChrisFrohlich | last post by:
ASP.NET 2.0 with Text DataTypes: I've got a similar question going in the SQL group, but I was wondering if anyone has successfully implemented reading/writing character data from a Text datatype...
6
by: bill | last post by:
Thanks to those that taught me to use heredoc to embed html in php. I don't want to start the html in php vs php in html discussion again., heredoc works a treat for that which I am doing...
2
by: someusernamehere | last post by:
hi, I have some heredoc on this way: $foo = <<<bar <form action="index.php" method="POST" name="user"> ............................................................................. HTML code...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.