I am working through this PHP & MySQL book and I have run into something quite different than what I am used to when it comes to echoing multiple lines of a single quoted string.
The example given is this:
echo '<table align="center" cellspacing="0" cellpadding="5" width="75%">
<tr>
<td align="left"><b>This</b></td>
<td align="left"><b>That</b></td>
<td align="left"><b>Then</b></td>
<td align="left"><b>When</b></td>
<td align="left"><b>What</b></td>
</tr>';
Obviously I could break out of PHP and use HTML, but this isn’t always an option. And when I don’t have that option I would usually break up my string for easier reading as such:
echo '<table align="center" cellspacing="0" cellpadding="5" width="75%">' .
'<tr>'
'<td align="left"><b>This</b></td>' .
'<td align="left"><b>That</b></td>' .
'<td align="left"><b>Then</b></td>' .
'<td align="left"><b>When</b></td>' .
'<td align="left"><b>What</b></td>' .
'</tr>';
The author of this book is well respected in the php community, and the book comes highly recommended and is reviewed well… So my question is this:
Is There anything wrong with his method and should this be practiced?
No, there’s nothing wrong with it at all. Just be aware that the spaces, tabs and line returns in the quoted string will be output as well. That’s rarely a problem – just something to remember.
To me, it’s a little easier to read and a little harder to get wrong than your way. In fact, your example has a syntax error. Can you find the missing dot?