Connecting Tech Pros Worldwide Help | Site Map

Code Conventions and preferences

julian maisano
Guest
 
Posts: n/a
#1: Jul 17 '05
A kind of survey...

1) what do yo prefer?

a)
echo '<table border="1" width="100%" border="0" cellspacing="0">';
?>

or
b)
?>
</table>

I mean, html inside php block or outside?

regards - jm
Shelly
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Code Conventions and preferences


I prefer the first if it is surrounded by other php statements. I don't
like hopping in and out of php.

Shelly

"julian maisano" <julianmaisanoXYZ@gmail.com> wrote in message
news:dbcggi$602$1@domitilla.aioe.org...[color=blue]
>A kind of survey...
>
> 1) what do yo prefer?
>
> a)
> echo '<table border="1" width="100%" border="0" cellspacing="0">';
> ?>
>
> or
> b)
> ?>
> </table>
>
> I mean, html inside php block or outside?
>
> regards - jm[/color]


R. Rajesh Jeba Anbiah
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Code Conventions and preferences


julian maisano wrote:[color=blue]
> A kind of survey...
>
> 1) what do yo prefer?
>
> a)
> echo '<table border="1" width="100%" border="0" cellspacing="0">';
> ?>
>
> or
> b)
> ?>
> </table>
>
> I mean, html inside php block or outside?[/color]

Seriously against to (a). Not sure, what is (b). I embed html inside
PHP and vice versa. I use echo only to output data, but never to output
html. Mine is:

<div id="main">
<?php
if ($foo)
{
?>
<p>Condition is true</p>
<?php
}
?>
<table summary="<?php echo $foo->getValue('summary');?>">
<tr>
<td><?php echo $foo->getValue('foo1');?></td><td><?php echo
$foo->getValue('foo2');?></td>
</tr>
<tr>
<td><?php echo $foo->getValue('foo3');?></td><td><?php echo
$foo->getValue('foo4');?></td>
</tr>
</table>
</div>

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com

no@emails.thx
Guest
 
Posts: n/a
#4: Jul 17 '05

re: Code Conventions and preferences


On Sat, 16 Jul 2005 23:40:55 -0500, julian maisano
<julianmaisanoXYZ@gmail.com> wrote:[color=blue]
>A kind of survey...
>
>1) what do yo prefer?
>
>a)
>echo '<table border="1" width="100%" border="0" cellspacing="0">';
>?>
>
>or
>b)
>?>
></table>
>
>I mean, html inside php block or outside?[/color]

I'd say it is all down to which predominates ... some of my pages are
purely HTML so they need no PHP. Others might just need a small bit of
database-derived information or some constants or included blocks etc
so i have the HTML surrounding one or two small <?php ... ?> areas.
But if the page is basically all includes and logic or data-derived
areas then i'd start with a <?php and finish with ?> and then echo
the HTML inside.

Basically, I agree with one of the other posters - avoid jumping in
and out of PHP because it makes the code very hard to follow and debug
later. Also, it's as much as anything down to readability and
presenting an intuitive source-code - so think of the person following
on from you who has to maintain the site - or even yourself a year on.
Put in plenty of comments describing what the script should do over
all - and then in more detail before major sections describing perhaps
why you chose to do the code in such a way.

Chris
Chung Leong
Guest
 
Posts: n/a
#5: Jul 18 '05

re: Code Conventions and preferences


Echoing HTML from PHP gets tricky when you have any embedded
Javascript. I usually break out of PHP when there's a large chunk of
HTML.

Norman Peelman
Guest
 
Posts: n/a
#6: Jul 21 '05

re: Code Conventions and preferences



"Chung Leong" <chernyshevsky@hotmail.com> wrote in message
news:1121701181.036632.42660@g47g2000cwa.googlegro ups.com...[color=blue]
> Echoing HTML from PHP gets tricky when you have any embedded
> Javascript. I usually break out of PHP when there's a large chunk of
> HTML.
>[/color]

What happens then???

Norm
---
Avatar Hosting at www.easyavatar.com


Closed Thread