Forum Moderators: coopster

Message Too Old, No Replies

echo function

         

electricocean

4:38 am on Feb 25, 2005 (gmt 0)

10+ Year Member



I made this script for plling news of the database and displaying it on the page. When I opened the site it said "Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /usr/export/www/hosting/dkicks/index.php on line 33'. Thats the echo funtion.

Line 33:
echo "<b><div align="left">DKicks :: News</div></b><br><br>";

Whats wrong?

electricocean

jatar_k

4:52 am on Feb 25, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



echo "<b><div align="left">DKicks :: News</div></b><br><br>";

you need to enclose the string to be echo'ed in quotes. As you will see above, the double quotes are opened right after the function echo and then closed right before the word left.

The parser then sees the word left and doesn't know what it is so it tells you there is an unexpected string.

There are two methods to correct this.

escape the quotes used inside the string, like so

echo "<b><div align=\"left\">DKicks :: News</div></b><br><br>";

to escape something you precede it with a \

the other option is to use single quotes around the string

echo '<b><div align="left">DKicks :: News</div></b><br><br>';

this means you don't get the mismatch of the different quotes. there is more information here on the differences between single and double quotes.
[php.net...]