Re: Couple of beginner questions

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

 



On Mon, 2009-01-12 at 19:43 +0000, Nathan Rixham wrote:
> Ashley Sheridan wrote:
> > On Mon, 2009-01-12 at 11:51 -0500, Frank Stanovcak wrote:
> >> "Ashley Sheridan" <> wrote in message 
> >> news:1231681793.3527.2.camel@xxxxxxxxxxxxxxxxxxxxxxxx
> >>> On Sun, 2009-01-11 at 08:08 -0500, tedd wrote:
> >>>> At 4:16 PM -0500 1/10/09, Paul M Foster wrote:
> >>>>> And let me present an alternative perspective. Never do something like:
> >>>>>
> >>>>> <?php echo 'Hellow world'; ?>
> >>>>>
> >>>>> Let Apache (or whatever) interpret HTML as HTML, and don't make it
> >>>>> interpret PHP code as HTML.
> >>>>>
> >>>>> Instead, do:
> >>>>>
> >>>>> <h1>Hello world</h1>
> >>>>>
> >>>>> If you're going to use PHP in the middle of a bunch of HTML, then only
> >>>>> use it where it's needed:
> >>>>>
> >>>>> <h1>Hello <?php echo $name; ?></h1>
> >>>>>
> >>>>> The contents of the PHP $name variable can't be seen by the HTML, which
> >>>>> is why you need to enclose it in a little PHP "island". Naturally, if
> >>>>> you're going to put PHP code in the middle of a HTML page, make the
> >>>>> extension PHP. Otherwise, Apache will not interpret the PHP code as PHP
> >>>>> (unless you do some messing with .htaccess or whatever). It's just
> >>>>> simplest to call a file something.php if it has PHP in it.
> >>>>>
> >>>>> Paul
> >>>>> --
> >>>>> Paul M. Foster
> >>>> Paul:
> >>>>
> >>>> I agree with you. My example was not well thought out. My point was
> >>>> not to mix style elements with data. I should have said:
> >>>>
> >>>> I would consider the following"bad practice":
> >>>>
> >>>>   <?php echo("<h1>$whatever</h1>"); ?>
> >>>>
> >>>> Whereas, the following I would consider "good practice".
> >>>>
> >>>> <h1><?php echo("$whatever"); ?></h1>
> >>>>
> >>>> Thanks for keeping me honest.
> >>>>
> >>>> Cheers,
> >>>>
> >>>> tedd
> >>>>
> >>>>
> >>>> -- 
> >>>> -------
> >>>> http://sperling.com  http://ancientstones.com  http://earthstones.com
> >>>>
> >>> Unless it's something like this:
> >>>
> >>> <?php
> >>> echo "<h1 class=\"$headerClass\">$whatever</h1>";
> >>> ?>
> >>>
> >>> Which is unlikely for a header tag, but I know this sort of format gets
> >>> used a lot by me and others, especially for setting alternate row styles
> >>> on tables (damn browsers and not supporting alternate rows!)
> >>>
> >>>
> >>> Ash
> >>> www.ashleysheridan.co.uk
> >>>
> >> Hey Ash...Why don't you just use CSS subclassing?
> >>
> >> <style type="text/css">
> >>     h1.odd {class stuff here}
> >>     h1.even {class stuff here}
> >> </style>
> >>
> >> then
> >>
> >> <h1 class="odd"><?php echo $whatever; ?></h1>
> >>
> >> no escaping, and no need to php your css styles.  :)
> >>
> >> Frank 
> >>
> >>
> >>
> > That's what I do do, but the 'odd' has to come from PHP, as
> > unfortunately, numerical selectors in CSS aren't supported by (AFAIK)
> > any browsers at the moment. So for example, if I was coding for
> > alternate rows in a table, I might do:
> > 
> > 
> > for($i=0; $i<$some_limit; $i++)
> > {
> >     $rowClass = ($i % 2 == 0)?'':'class="alternate"';
> >     print <<<EOP
> >     <tr $rowClass>
> >         <td>...</td>
> >         <td>...</td>
> >         <td>...</td>
> >     </tr>
> > EOP;
> > }
> > 
> > As far as such loops go, is this a particular faux pas in regards to the
> > way it's coded? Go on Tedd ;)
> > 
> > 
> > Ash
> > www.ashleysheridan.co.uk
> > 
> 
> nice pick-up on the fact you only need to css the alternate row not both 
> odd and even :p
> 
Yeah, I think my laziness had something to do with that, I didn't want
to have to go and define another style ;)


Ash
www.ashleysheridan.co.uk


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[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