NYCPHP Meetup

NYPHP.org

[nycphp-talk] 'In and out' of php

Mark Armendariz nyphp at enobrev.com
Fri Jan 23 15:06:25 EST 2004


Later today or this weekend, I'm hoping to find some time to run my own
tests, but I was wondering if any of you talented people have any idea...
 
I tend to try to seperate my php and xhtml as much as i can, but when I do
have to use php within my html (for loops for instance), I try to put ONLY
php code and vars in php tags and I exit php for ALL html.  
 
for instance i try to:
 
<table id="items>
<tr>
    <td><a href="index.php?page=<?= $_GET['page'] ?>&sort=id">ID</a></td>
    <td><a href="index.php?page=<?= $_GET['page']
?>&sort=title">Title</a></td>
</tr>
<?php foreach($items as $item) { ?>
    <tr>
        <td><?= $item['item_id'] ?></td>
        <td><b><?= $item['item_title'] ?></b></td>
    </tr>
<?php } ?>
</table>
 
 
instead of:
 
<table id="items>
<tr>
    <td><?= '<a href="index.php?page=' . $_GET['page'] . '&sort=id">ID</a>'
?></td>
    <td><?= '<a href="index.php?page=' . $_GET['page'] .
'&sort=title">Title</a>' ?></td>
</tr>
<?php
    $output = '';
    foreach($items as $item) {
        $output .= '<tr>' . "\n";
        $output .= '<td>' . $item['item_id'] . '</td>' . "\n";
        $output .= '<td><b>' . $item['item_title'] . '</b></td>' . "\n";
        $output .= '</tr>' . "\n";
    }
    echo $output;
?>
</table>
 
My primary reasons for keeping it seperate are, for one for readability,
especially in editors with  good color coding like DW which color both the
html and the php pretty well, and also so when a designer looks at the code,
usually using DWMX, they can see all thier html right away and can work
around the php stuff a bit easier without worrying that some html might be
ocming from my stuff.
 
So my question: Is going 'in and out' of php as such expensive?  Does it
take more memory or added processing?
 
It seems like a minor issue for something as small as a basic table loop,
but when putting all the elements of a full site together, every ms counts.
 
Thanks!
 
Mark





More information about the talk mailing list