[KLUG Members] php and quotation marks
Richard Harding
rick at ricksweb.info
Tue Sep 27 15:09:09 EDT 2005
On Tue, 2005-09-27 at 14:46 -0400, bill wrote:
> On Tue, 2005-09-27 at 14:30, Richard Harding wrote:
>
> >
> > 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.
>
> O.K., but what would this look like?
>
> echo "<tr><td>$name</td><td>$date</td><td>$status</td><td>$r</td></tr>";
>
> You'd end up with
>
> print '<tr><td>' . $name . '</td><td>' . $date . '</td><td>' . $status
> . '</td><td>' . $r . '</td></tr>";
>
> After a while, concantenation becomes too long and unreadable. The
> first line is simpler.
>
> kind regards,
>
> bill
That's what newlines are for :)
print '<tr>' .
'<td>' . $name . '</td>' .
'<td>' . $date . '</td>' .
'<td>' . $status . '</td>' .
'<td>' . $r . '</td>' .
'</tr>';
It's readable and you can still format the HTML so that columns line up
nicely for matching <tr> and <td> tags. Helps on those complex tables.
On some things I even line up each column with it's own tab so that all
the <td> $var </td> are in their own column straight down.
Although with my sql statements I tend to use heredoc syntax
$query = <<<END
SELECT * FROM table WHERE
var1 = '$var1' AND
var2 = '$var2';
END;
Just some more input.
More information about the Members
mailing list