Forum Moderators: coopster
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/trial/public_html/forms.php on line 414
This is the part of the code that shows the error - line 414
++++++++++++++++++++++++++++++++++++
} else {
echo "<body><font face="Verdana" size="2"> </font><table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="756">
<tr>
<td width="179">
<a href="http://www.mydomain/index.htm">
<img border="0" src="http://www.mydomain.com/images/logo.gif" alt=""></a></td>
<td width="577">
<p align="right"><b><font face="Verdana" size="2"><a href="http://www.mydomain.com/index.htm">
<font color="#AD1818">Home</font></a></font></b></td>
</tr>
</table>
<table border="0" width="758" height="250">
<tr>
<td width="738" height="33" colspan="2" valign="top">
<p align="center"><b><font face="Arial" size="4">Thank You for your
enquiry. We will get back to you very soon. </font>
<font face="Arial" size="4" color="#ad1818"> </font></b></td>
</tr>
</table>
</body>\n";
exit;
}
// <---------- THE END ----------> //
"<body><font face="Verdana" size="2">
PHP thinks your string ends at the first opening quote of the font attribute.
Personally I like to validate all script output, and although single quotes are "valid" I use the classic style of double quoted attributes in html, so I use single quotes for hard-coded output and concatenate for inline variables.
echo '<body><font face="Verdana" size="2">'.$some_var.</font>';
But if you have a lot of inline variables, it may be easier to take henry0's approach:
echo "<body><font face=\"Verdana\" size=\"2\">$some_var</font>";
Which gives the "toothpick syndrome." :-) Since you're using font tags which won't validate anyway, either should be fine.
I'll never understand why PHP doesn't have the equivalent of perl's multiline qq, in which all these go away. or does it?
.... no double quotes in between...
No don't do that.
echo "<font face=Verdana size=2>$some_var</font>";
While this "works," unquoted attributes are a really bad habit to form. As an example, what if you have CSS classes named "right-align" and "emphasis-style" (color= red) and to apply both without writing a new selector, you would do
<p style="right-align emphasis-style">I'm red and right-aligned</p>
But without quoting,
<p style=right-align emphasis-style>I'm red and right-aligned</p>
This would most likely fail, and the absence of quotes could cause whole blocks of text to disappear in the browser even if it's in the source code.
I's still recommend the single quote or "toothpick syndrome" escape approach. As a programmer you just want to get the job done, but there's nothing wrong with getting it done right. Get your head around how PHP manages raw text and quoting and it will become very easy to manage.
By the way my single-quoted example had an error, was missing a single quote (doh.)
echo '<body><font face="Verdana" size="2">'.$some_var.'</font>';