[KLUG Members] php and quotation marks

Richard Harding rick at ricksweb.info
Tue Sep 27 14:30:43 EDT 2005


On Tue, 2005-09-27 at 14:26 -0400, bill wrote:
> On Tue, 2005-09-27 at 14:00, Richard Harding wrote:
> 
> > > bill
> > I'm the opposite. I much prefer to see a separation of html and
> > variables. By using single quotes you're forced to use the . to
> > concatenate the string and it's much easier to see where content is
> > coming from than searching strings for $ that may or may not be there. 
> 
> A lot of people think that, but I almost never use the . concantenation.
> 
> echo "<P align=\"center\">The name is $myvariable.</p>";
> 
> The above line works perfect, is easier than anything else to read, and
> handles variables with ease.
> 
> This is harder to read:
> 
> echo '<p align="center">' . "The name is $myvariable" . '</p>';
> 
> Or even worse
> 
> <p align="center">
> 
> <?php 
> 
> echo "The name is $myvariable";
> 
> ?>
> 
> </p>
> 
> They all work, but the first is much easy to scan and modify without
> screwing something up.

My version would look like:
print '<p align="center">The name is ' . $myvariable . '</p>';

The variable stands out cleanly from the non-php. I have no problems
with ' this way. Just personal preference, but I thought I would share. 

Rick



More information about the Members mailing list