|
Posted by Rik on 01/04/07 21:58
Michael wrote:
> Hi,
>
> A quick and most likely simply question about which is generally
> better programming with PHP. Is it more proper to break out of PHP
> code to write HTML, or is it ok rto do it within print() statements?
> Such as...
>
> SCRENARIO A)
> <?php
> ...code...
>>
> <img src="<?=$imgsrc?>">
> <?php
> ...more code...
>>
>
> SCENARIO B)
> <?php
> ...code...
> print("<img src=\"".$imgsrc."\">");
> ...more code...
It highly depends, and there is no easy answer. I usually break out of php
for large blocks, and stay inside for small bits.
However, the reason I post;
1. <?=$imgsrc?> is a Bad Thing
It can work, no question about that, but always try to use a proper
<?php echo ''; ?>.
2. print("<img src=\"".$imgsrc."\">");
Better would be either print("<img src=\"{$imgsrc}\">"); or print('<img
src="'.$imgsrc.'">');
Grtz,
--
Rik Wasmus
[Back to original message]
|