PHP Heredoc unexpected end of file error
That specific error can result from white-space / tab indentation on the same line after the closing HEREDOC:
Most people catch the opening white-space issue, this one is obviously harder to see.
When in doubt with HEREDOC blocks try and eliminate all possible white-space and indentations.
Possible Dupe: Why do these Heredoc and Nowdoc cause errors?
here-document gives 'unexpected end of file' error
The EOF
token must be at the beginning of the line, you can't indent it along with the block of code it goes with.
If you write <<-EOF
you may indent it, but it must be indented with Tab characters, not spaces. So it still might not end up even with the block of code.
Also make sure you have no whitespace after the EOF
token on the line.
PHP Unexpected end of file
You appear to have some spaces after your heredoc closing identifier.
From the manual:
It is very important to note that the line with the closing identifier
must contain no other characters, except a semicolon (;). That means
especially that the identifier may not be indented, and there may not
be any spaces or tabs before or after the semicolon.
Parse error: syntax error, unexpected $end
The HereDOC ( $og_video = <<<HTML )
is wrong, it has to be a the direct start of a line.
Check: http://php.net/manual/en/language.types.string.php for details on this.
Also remove any whitespace after HTML, that causes errors too.
Otherwise, there's really nothing wrong with it, should work quite nicely.
in bash, heredoc inside function returns syntax error
Your function declaration is wrong:
get_instance{
should be one of
function get_instance {
get_instance() {
Put the close bracket on a different line:
dbname=$(sqlplus -s / as sysdba<<EOF
...
EOF
)
The terminating word of the heredoc should be the only characters on the line (except tabs when using <<-
). Demo:
$ x=$(cat <<END
> one
> two
> END)
bash: warning: here-document at line 5 delimited by end-of-file (wanted `END')
$ echo "$x"
one
two
So it worked, accidentally. Better practice is:
$ y=$(cat <<END
> 1
> 2
> END
> )
$ echo "$y"
1
2
Heredoc not working
The parser is complaining because you have whitespace after the angled brackets declaring a heredoc. You need to make sure you're actually following the heredoc syntax, which you can find on the PHP Manual site (specifically: http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc).
<?php
$information = <<<ENDHEREDOC
this is my text
ENDHEREDOC;
echo $information;
here document - unexpected end of file
The <<-
form of here documents are very sensitive to leading whitespace. They only allow for tabs. If you accidentally used leading space or your editor expands tabs automatically, the here document would never find its closing token, and that would account for the error you see.
If you want to maintain your indentation, but want an alternative to the <<-
notation, consider just using echo
or printf
, like so:
report() {
printf '<H2>%s</H2>\n<PRE>%s</PRE>\n' "$1" "$2"
}
report_home_space() {
report 'Home Space Utilization' "$(du -sh ~/*)"
}
# Other reports as above...
Related Topics
Pdo Were Rows Affected During Execute Statement
Simple PHP Echo Code Not Working
PHP How to Remove Last Part of a Path
File_Get_Contents Returns Empty String
How to Search Array for Multiple Values in PHP
Sending/Displaying a Base64 Encoded Image
How to Pass an Array of Pdo Parameters Yet Still Specify Their Types
What Means Call to a Member Function on Boolean and How to Fix
Convert PHP Array String into an Array
Using Return in Ternary Operator
Multiple Http Get Parameters with the Same Identifier
Checking Browser's Language by PHP