Re: Re: PHP in HTML code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Mar 18, 2010 at 1:37 PM, Ashley Sheridan
<ash@xxxxxxxxxxxxxxxxxxxx>wrote:

> On Thu, 2010-03-18 at 18:37 +0100, Jan G.B. wrote:
>
> >
> >
> > 2010/3/18 Ashley Sheridan <ash@xxxxxxxxxxxxxxxxxxxx>
> >
> >
> >         On Thu, 2010-03-18 at 18:09 +0100, Jan G.B. wrote:
> >
> >         > 2010/3/18 Ashley Sheridan <ash@xxxxxxxxxxxxxxxxxxxx>
> >         >
> >         > >  I'd rather have short tags turned off than remember each
> time that I have
> >         > > to keep breaking up the < and ?php before I output it in-case
> the parser
> >         > > gets confused.
> >         > >
> >         >
> >         > You don't need to break anything up. It's perfectly valid and
> without
> >         > problems:
> >         >
> >         > <?php echo '<?xml version.... ?>'; ?>
> >
> >
> >
> >
> >         What about this:
> >
> >         <?xml version="1.0">
> >         <?php
> >
> >
> >
> >
> >
> > It's confusing! =)
> >
> >
> >         That would break with short tags turned on. I often use this
> >         sort of code in my Ajax server stuff. I don't want to have to
> >         use PHP to echo out what would work on a normal setup.
> >
> >
> > I can understand it. But I think it's nonsense to output one line of
> > "text" (prolog) and then start with <?php - while arguing that the
> > first line of PHP should not be an echo. Where's the point?
> >
> >
> >
> >
> >
> >
> >         Thanks,
> >         Ash
> >         http://www.ashleysheridan.co.uk
> >
> >
> >
> >
> >
>
>
> That was just a really small example. Imagine the <?xml line followed by
> other lines of actual XML content that might remain static:
>
> <?xml version="1.0">
> <content>
>    <other_stuff/>
>    <even_more_stuff/>
>    <?php
>    // code that changes here
>    ?>
> </content>
>
> I could use heredoc or nowdoc, but why that's just ugly, and the
> resulting XML inside the heredoc/nowdoc isn't recognised as XML by any
> editor I know of. All of that to avoid writing a few extra characters to
> "save myself some work"...
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>

   - 310 characters.
   - Differentiation between code that's merely echoed and code that
   performs some operation.
   - XML is recognized by editors.
   - Easier for me to visually scan.

<?=  '<?xml version="1.0">' ?>
<content>
   <?php foreach ($rows as $row)  { ?>
   <row>
      <title><?= $row['title'] ?></title>
      <type><?= $row['type'] ?></type>
      <desc><?= $row['desc'] ?></desc>
      <date><?= $row['date'] ?></date>
      <other><?= $row['other'] ?></other>
   </row>
   <? } ?>
</content>




   - 340 characters.
   - All code blocks consistent.
   - XML recognized by editors.


<?xml version="1.0">
<content>
   <?php foreach ($rows as $row)  { ?>
   <row>
      <title><?php echo $row['title']; ?></title>
      <type><?php echo $row['type']; ?></type>
      <desc><?php echo $row['desc']; ?></desc>
      <date><?php echo $row['date']; ?></date>
      <other><?php echo $row['other']; ?></other>
   </row>
   <? } ?>
</content>

Given the choice, I'd rather work with the first option, but I have no
problem with those who prefer the second option.

Adam

-- 
Nephtali:  PHP web framework that functions beautifully
http://nephtaliproject.com

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux