Click here to Skip to main content
11,805,035 members (61,614 online)
Rate this: bad
Please Sign up or sign in to vote.
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:
$myFile = "servers.txt";
line 8:
$fh = fopen($myFile, 'a') or die("can't open file");
line 9:
$stringData = <<<EOD
line 10:
<a href="$_POST['title'].html">$_POST['title']</a><br> \n
line 12:
line 13:
fwrite($fh, $stringData);
line 14:

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 12-Jul-13 16:12pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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:
$stringData = <<<EOD
<a href="{$_POST['title']}.html">{$_POST['title']}</a><br> \n
Jaydman2102 at 13-Jul-13 1:38am
Thanks for the reply! Now I can make a forum completely without MySQL.
Jaydman2102 at 13-Jul-13 13:08pm
I have a question. Is it mandantor to put "\n" In a heredoc or will it automatically break?
Jaydman2102 at 13-Jul-13 13:17pm
Another problem arose. I get an undefined index wherever a variable in {} is.
thanh_bkhn at 13-Jul-13 20:03pm
How did you use your index, and what is your error message?
Jaydman2102 at 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)

  Print Answers RSS
0 OriginalGriff 315
1 CPallini 210
2 Richard Deeming 200
3 Sergey Alexandrovich Kryukov 168
4 CHill60 150
0 OriginalGriff 3,255
1 Maciej Los 1,990
2 KrunalRohit 1,907
3 CPallini 1,855
4 Richard MacCutchan 1,227

Advertise | Privacy | Mobile
Web03 | 2.8.151002.1 | Last Updated 13 Jul 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100