FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Why "unexpected T_ENCAPSED_AND_WHITESPACE"?





devroom
Hi

This code:
Code:
$buffer = "<?php\n".
   "$config = array();\n".
   "$config['maxmessages'] = '$maxmessages';\n".
   "$config['blockusers'] = '$blockusers';\n".
   "$config['mailonnew'] = '$mailonnew';\n".
   "?>";


Gives this error:
Quote:
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\Program Files\wamp\www\administrator\components\com_pms\admin.pms.php on line 58


I want it to be inserted and this is the code that needs to be inserted.

Somebody knows how to fix this?

Grtz and thx

Edit: inserted a wrong code. Changed that now.
hexkid
devroom wrote:
Somebody knows how to fix this?

I do! Smile

You are having troubles because of variable parsing. Follow the rules for double quoted strings or use single quotes.

All these work and do the same, which may not be what you want!
Code:
$buffer .= "$config[maxmessages] = '$maxmessages'&amp;\n";

Code:
$buffer .= "{$config['maxmessages']} = '$maxmessages'&amp;\n";

Code:
$buffer .= $config['maxmessages'] . ' = \''. $maxmessages . "'&amp;\n";
Esch
It seems easier to me to simply escape the dollar sign using a backslash rather than mess with the differences between the quotes; e.g.:

Code:
$buffer = "<?php\n".
   "\$config = array()&amp\n".
   "\$config['maxmessages'] = '\$maxmessages'&amp\n".
   "\$config['blockusers'] = '\$blockusers'&amp\n".
   "\$config['mailonnew'] = '\$mailonnew'&amp\n".
   "?>";

Hope that helps somewhat.
Related topics
Why our life is like that...
Code help
Why Women Cheat?
Vraagje over PHP
Parse Error in PHP I can't figure out.
Problems with a Guess a Number Code.
Why do people start topics and/or post replies here?
Problems with php + mysql script.
Problem with Member system(or template) and $_GET[id]
php msql problem
Why is calling a Jew, "Jew", a crime?
Unexpected T_STRINGS *Resolved*
Editing files online
Reflections on Why We Need to Write
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.