sam06 Posted June 15, 2007 Share Posted June 15, 2007 Hi, My page main.php seems fine to me, but it keeps coming up with unexpected T_String. It might be something to do with escaping single and double quotes, but I'm not sure. The code (starting with line 36) is ."[<a href="userinfo.php?user=$session->username">My Account</a>] " ."[<a href="useredit.php">Edit Account</a>] "; if($session->isAdmin()){ echo "[<a href="admin/admin.php">Admin Center</a>] "; } echo "[<a href="process.php">Logout</a>]"; } else{ ?> The Error I get is Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/sam06/public_html/gff/main.php on line 36 If anyone could tell me where I've gone wrong, I'd be very helpful. Thanks very much, Sam Quote Link to comment https://forums.phpfreaks.com/topic/55774-solved-unexpected-t_string-help/ Share on other sites More sharing options...
dsaba Posted June 15, 2007 Share Posted June 15, 2007 show us line 36 or the lines around it, not the whole script $2 dollars chigley is gonna basically repeat my post in the next following post Quote Link to comment https://forums.phpfreaks.com/topic/55774-solved-unexpected-t_string-help/#findComment-275550 Share on other sites More sharing options...
chigley Posted June 15, 2007 Share Posted June 15, 2007 Can you just paste the relevant lines please? Quote Link to comment https://forums.phpfreaks.com/topic/55774-solved-unexpected-t_string-help/#findComment-275552 Share on other sites More sharing options...
AndyB Posted June 15, 2007 Share Posted June 15, 2007 Before you paste any code - relevant or otherwise - you might as well go through and fix as many problems as you recognize. echo treats everything between consective matching quotes as the string to be output, and expect whatever follows the closing quote to be a php instruction. For example, the following will crap out: echo "[<a href="process.php">Logout</a>]"; It gets treated as echo "[<a href=" followed by the incomprehensible instruction process. echo "[<a href='process.php'>Logout</a>]"; // works perfectly Quote Link to comment https://forums.phpfreaks.com/topic/55774-solved-unexpected-t_string-help/#findComment-275566 Share on other sites More sharing options...
dsaba Posted June 16, 2007 Share Posted June 16, 2007 yes andyB is right if however if you don't want to change the html code you can escape the double quotes like so: echo "[<a href=\"process.php\">Logout</a>]"; study these lines: echo '[<a href="process.php">Logout</a>]'; and: echo "[<a href=\"process.php\">Logout</a>]"; both of those will output the same thing without changing any of the html code, a rule of thumb is if you are enclosing the string in double quotes (" ") and part of the string contains double quotes you need to escape the quotes inside the string with a \ same thing goes for strings encapsed in single quotes ( ' ' ) where a single quote is part of the string on a side note: I don't know what you're trying to do with the brackets [ ] around the html in the first place, I'm not familiar with them, but I do know that if you simply want to output this html: <a href="process.php">Logout</a> you can do it simply like this: echo '<a href="process.php">Logout</a>'; without the enclosing brackets Quote Link to comment https://forums.phpfreaks.com/topic/55774-solved-unexpected-t_string-help/#findComment-275647 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.