Click here to Skip to main content
15,907,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have a php file. I get this error:


Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\wamp\www\spost.php on line 10

This is what on line 10 and before and after:
line 7:
PHP
$myFile = "servers.txt";

line 8:
PHP
$fh = fopen($myFile, 'a') or die("can't open file");

line 9:
PHP
$stringData = <<<EOD

line 10:
PHP
<a href="$_POST['title'].html">$_POST['title']</a><br> \n

line 12:
PHP
EOD;

line 13:
PHP
fwrite($fh, $stringData);

line 14:
PHP
fclose($fh);



I dont know what the problem is. I thought heredoc let me put variables in. I THINK it has
To do with the variables, because I took that block out and I got another error where another
variable was in yet another heredoc place.

What is the issue and how can I solve it?
Posted

1 solution

It's not about your heredoc, it's just a wrong using of variable name inside a string of PHP.
String doesn't let you put array element directly inside it without curry braces.
Try this:
PHP
$stringData = <<<EOD
<a href="{$_POST['title']}.html">{$_POST['title']}</a><br> \n
EOD;
 
Share this answer
 
v2
Comments
G4mm4R4y 13-Jul-13 1:38am    
Thanks for the reply! Now I can make a forum completely without MySQL.
G4mm4R4y 13-Jul-13 13:08pm    
I have a question. Is it mandantor to put "\n" In a heredoc or will it automatically break?
G4mm4R4y 13-Jul-13 13:17pm    
Another problem arose. I get an undefined index wherever a variable in {} is.
thanh_bkhn 13-Jul-13 20:03pm    
How did you use your index, and what is your error message?
G4mm4R4y 14-Jul-13 2:09am    
Fixed anyway

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900