What wrong with my code here? T_String error?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
joseph
Forum Newbie
Posts: 24
Joined: Mon Jul 03, 2006 6:15 am

What wrong with my code here? T_String error?

Post by joseph »

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/sitename/public_html/php/feedback.php on line 2027

Code: Select all

if (mail($recipient,$subject,$message,$headers)) {
   echo '
Line 2027:

Code: Select all

<b>',Thank You $Title $FirstName $Lastname'</p><a href="www.sitename.com/english/thank_you.html">'Click Here,'</b>'; 
} else {
   echo '
   <a href="www.sitename.com/english/thank_you.html">',Back,'</a>';   
}
?>
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Show more of your code
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Well I can see the problem before you post further code.

What string delimters are you using? Single quotes or double quotes? Either way you have them in your string unescaped. Use backslashes to escape those characters ;)
User avatar
MarK (CZ)
Forum Contributor
Posts: 239
Joined: Tue Apr 13, 2004 12:51 am
Location: Prague (CZ) / Vienna (A)
Contact:

Post by MarK (CZ) »

Also, I don't understand why are there so many single quotes? It seems to me that on both sides of many quotes is text that should be enclosed in some quotes.

IMO this should do it:

Code: Select all

if (mail($recipient,$subject,$message,$headers)) {
  echo "<b>Thank You $Title $FirstName $Lastname</p>".
       "<a href=\"www.sitename.com/english/thank_you.html\">Click Here</b>";
} else {
   echo "<a href=\"www.sitename.com/english/thank_you.html\">Back</a>";
}
joseph
Forum Newbie
Posts: 24
Joined: Mon Jul 03, 2006 6:15 am

Post by joseph »

Thanks guys! :D Worked fine now. Does the double quote and single quote has the same functions?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Examples

Code: Select all

$name = "Mark";

echo "My name is $name";

// outputs: My name is Mark

Code: Select all

$name = "Mark";

echo 'My name is $name';

// outputs: My name is $name

Code: Select all

$name = "Mark";

echo 'My name is '.$name;

// outputs: My name is Mark
Ward
Forum Commoner
Posts: 74
Joined: Thu Jul 13, 2006 10:01 am

Post by Ward »

Instead of using the echo statement, you can always use the ?> <? tags to output HTML. This way you don't have to worry about escaping quotes, and you will get HTML syntax coloring in your editor.

Pimptastic's example of double vs single quotes is good. Double quotes will resolve variables to their values, single quotes will not.

For example:

Code: Select all

if (mail($recipient,$subject,$message,$headers))
{
?>
     <b>Thank You <?=$Title?> <?=$FirstName?> <?=$Lastname?></p>
     <a href="www.sitename.com/english/thank_you.html">Click Here</b>
<?
} else {
?>
     <a href="www.sitename.com/english/thank_you.html">Back</a>  
<?
}
?>
It's probably not the best or most attractive method, but it does work. I use it when I need to output large blocks of HTML, mostly because of the HTML syntax coloring thing.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Single quotes = string literal. Whatever is in the single quotes gets echo'ed as such.

Double quotes = parsed/evaluated string.

There is a lot of good information on strings in the PHP manual.
joseph
Forum Newbie
Posts: 24
Joined: Mon Jul 03, 2006 6:15 am

Post by joseph »

@Everah, @Ward, @Pimptastic, @MarK (CZ):

Thanks for all your help! :D
User avatar
MarK (CZ)
Forum Contributor
Posts: 239
Joined: Tue Apr 13, 2004 12:51 am
Location: Prague (CZ) / Vienna (A)
Contact:

Post by MarK (CZ) »

Everah wrote:Single quotes = string literal. Whatever is in the single quotes gets echo'ed as such.
Except \' (') and \\ (\) entities :)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

MarK (CZ) wrote:
Everah wrote:Single quotes = string literal. Whatever is in the single quotes gets echo'ed as such.
Except \' (') and \\ (\) entities :)
Sorry, I should have mentioned that.
Post Reply