Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/55774-solved-unexpected-t_string-help/
Share on other sites

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.