使用HEREDOC时出现PHP错误 [英] PHP Error when using HEREDOC
问题描述
我有一个php文件。我收到此错误:
解析错误:语法错误,意外''(T_ENCAPSED_AND_WHITESPACE),期待标识符(T_STRING)或变量( T_VARIABLE)或数字(T_NUM_STRING)在第10行C:\ wamp \\\spost.php
这是第10行以及之前和之后的内容:
第7行:
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";
第8行:
line 8:
$fh = fopen($myFile, 'a') or die("can't open file");
第9行:
line 9:
$stringData = <<<EOD
第10行:
line 10:
<a href="$_POST['title'].html">$_POST['title']</a><br> \n
第12行:
line 12:
EOD;
第13行:
line 13:
fwrite($fh, $stringData);
第14行:
line 14:
fclose($fh);
我不知道问题是什么。我以为heredoc让我把变量放进去。我认为它有
要做变量,因为我把那个块拿出去了,我又得到了另一个错误,那就是另一个
变量是在另一个heredoc地方。
有什么问题,如何解决?
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?
推荐答案
myFile = servers.txt;
myFile = "servers.txt";
第8行:
line 8:
fh = fopen(
fh = fopen(
myFile,' a')或 die( 无法打开文件);
myFile, 'a') or die("can't open file");
第9行:
line 9:
这篇关于使用HEREDOC时出现PHP错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!