[ciapug] Peer review of PHP code

David Champion ciapug@cialug.org
Tue, 13 Apr 2004 11:19:06 -0500


Barry Von Ahsen wrote:

>
> but trying to syntax check (specificaly to validate the html) it 
> usually barfs on the php.  especially when I'm making table rows in a 
> loop; if I have something like:
> <? if($i%2 == 0) { ?>
>     <tr bgcolor="#eeeeee">
> <? } else { ?>
>     <tr bgcolor="#ffffff">
> <? } ?>
>     <td>stuff</td>
> </tr>
> it will complain "No starting tag found for: "tr", or it was closed 
> too many times".  I see it's there, but only because I'm mentally 
> interpreting the php, if I were to give it just the final output (like 
> you do) it would be fine.
>
> -barry

Easy to fix:

<?
if($i%2 == 0) {
    $bgcolor = "#eeeeee";
} else {
    $bgcolor = "#ffffff";
}
?>
    <tr bgcolor="<?= $bgcolor ?>">
      <td>stuff</td>
    </tr>

-dc