Writing to Heredoc from Text Area Form

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matt F

    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">Templ ate 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($templa te)
    accordingly.
  • Schraalhans Keukenmeester

    #2
    Re: Writing to Heredoc from Text Area Form

    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">Templ ate 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($templa te)
    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 - schraalhans@the .spamtrapexampl e.nl
    [Remove the lowercase part of Spamtrap to send me a message]

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

    Comment

    • Matt F

      #3
      Re: Writing to Heredoc from Text Area Form

      On Thu, 31 May 2007 17:22:49 +0200, Schraalhans Keukenmeester <Schraalhans@th e.spamtrapexamp le.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

      Comment

      Working...