[FX.php List] Risks in multi-line echo statement?

Gjermund Gusland Thorsen ggt667 at gmail.com
Sun Oct 29 04:02:00 MST 2006


Noticably I put the making of $table above the HTML,
any errors I output inside body,
and the echo $table; inside body.

ggt667

On 10/26/06, Joel Shapiro <jsfmp at earthlink.net> wrote:
> Thanks Gjermund.  I hadn't thought of anything like that.
>
> Best,
> -Joel
>
>
> On Oct 26, 2006, at 1:47 AM, Gjermund Gusland Thorsen wrote:
>
> > This would be my approach:
> >
> > $col[] = '<td align="right">Field A: </td>';
> > $col[] = '<td>' . $value['FieldA'][0] . '</td>';
> >
> > $row[] = '<tr>' . implode( "\n\t\t", $col ) . '</tr>';
> > unset( $col );
> >
> > $col[] = '<td align="right">Field B: </td>';
> > $col[] = '<td>'.$value['FieldB'][0].'</td>';
> >
> > $row[] = '<tr>' . implode( "\n\t\t", $col ) . '</tr>';
> > unset( $col );
> >
> > $table = '<table>' . implode( "\n\t", $row ) . '</table>';
> >
> > echo $table;
> >
> > ggt667
> >
> > On 10/25/06, Joel Shapiro <jsfmp at earthlink.net> wrote:
> >> Thanks Chris, that's great!  I'd never heard of heredoc.
> >>
> >> looking at its php.net documentation lead me to the echo()
> >> documentation, which includes:
> >>
> >> echo <<<END
> >> This uses the "here document" syntax to output
> >> multiple lines with $variable interpolation. Note
> >> that the here document terminator must appear on a
> >> line with just a semicolon. no extra whitespace!
> >> END;
> >>
> >> (so you're right, you don't need to store the heredoc in a variable)
> >>
> >> it also includes:
> >>
> >> echo "This spans
> >> multiple lines. The newlines will be
> >> output as well";
> >>
> >> (which I guess answers my original question)
> >>
> >> Best,
> >> -Joel
> >>
> >>
> >> On Oct 25, 2006, at 11:08 AM, Chris Hansen wrote:
> >>
> >> > Joel,
> >> >
> >> > Use heredoc syntax.  This would like like the following:
> >> >
> >> > $myText = <<<MY_TEXT
> >> > <table>
> >> >       <tr>
> >> >               <td align="right">Field A: </td>
> >> >               <td>{$value['FieldA'][0]}</td>
> >> >       </tr>
> >> >       <tr>
> >> >               <td align="right">Field B: </td>
> >> >               <td>{$value['FieldB'][0]}</td>
> >> >       </tr>
> >> > </table>
> >> > MY_TEXT;
> >> >
> >> > echo($myText);
> >> >
> >> > Note that like double quotes, your variables can go right inside
> >> > the block.  Also, heredoc is designed to work with multi-line
> >> > blocks of text.  The PHP online docs have more details:
> >> >
> >> > http://www.php.net/manual/en/
> >> > language.types.string.php#language.types.string.syntax.heredoc
> >> >
> >> > Lots of folks aren't aware of this string syntax, but it's a gem in
> >> > my opinion.  (You may be able to echo the heredoc block directly
> >> > rather than storing it first -- I don't use it that way
> >> though.)  HTH
> >> >
> >> > --Chris Hansen
> >> >   FileMaker 7 Certified Developer
> >> >   Creator of FX.php
> >> >   "The best way from FileMaker to the Web."
> >> >   www.iViking.org
> >> >
> >> >
> >> > On Oct 25, 2006, at 11:51 AM, Joel Shapiro wrote:
> >> >
> >> >> Hi all
> >> >>
> >> >> Quick php formatting question:
> >> >>
> >> >> Are there any risks to using a single echo statement with multiple
> >> >> lines inside the quotes, as follows?
> >> >>
> >> >> echo ' // START ECHO
> >> >> <table>
> >> >>      <tr>
> >> >>              <td align="right">Field A: </td>
> >> >>              <td>'.$value['FieldA'][0].'</td>
> >> >>      </tr>
> >> >>      <tr>
> >> >>              <td align="right">Field B: </td>
> >> >>              <td>'.$value['FieldB'][0].'</td>
> >> >>      </tr>
> >> >> </table>
> >> >> '; //  END ECHO
> >> >>
> >> >> I think it was on this list where people once discussed various
> >> >> ways of switching between html and php code.  This way *seems* to
> >> >> be a way to keep the html looking like html (both in the initial
> >> >> code, and in the browser's view source), but without needing lots
> >> >> of echo statements (1 per line), or using "\n", or having to
> >> use <?
> >> >> php echo $value['FieldA'][0]; ?> each time within straight html.
> >> >> I've looked elsewhere online and haven't found other examples of
> >> >> this, so I'm wondering if there's a good reason for that.
> >> >>
> >> >> TIA,
> >> >> -Joel
> >> >> _______________________________________________
> >> >> FX.php_List mailing list
> >> >> FX.php_List at mail.iviking.org
> >> >> http://www.iviking.org/mailman/listinfo/fx.php_list
> >> >>
> >> >
> >> > _______________________________________________
> >> > FX.php_List mailing list
> >> > FX.php_List at mail.iviking.org
> >> > http://www.iviking.org/mailman/listinfo/fx.php_list
> >>
> >> _______________________________________________
> >> FX.php_List mailing list
> >> FX.php_List at mail.iviking.org
> >> http://www.iviking.org/mailman/listinfo/fx.php_list
> >>
> > _______________________________________________
> > FX.php_List mailing list
> > FX.php_List at mail.iviking.org
> > http://www.iviking.org/mailman/listinfo/fx.php_list
>
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list
>


More information about the FX.php_List mailing list