Jump to content

weird $end error...


WhiteRau

Recommended Posts

tore the forum apart looking for a solution to this one.  for some reason, this is generating an 'unexpected $end' error.  this is ALL the code.  in entirety. i was just messing around getting familiar with filesystem stuff.  no short tags.  no curly brackets.  so... :wtf:

 

<?php
$fileHandler = fopen("someFile.txt", 'w') or die ("could not create file");
$text = <<<_END
drop some text
and some stuff
plus this stuff
some other stuff

_END;
fwrite($fileHandler, $text) or die ("could not write to file");
fclose($fileHandler);
echo "File 'someFile.txt' written successfully";
?>

 

thanks people.  this has be stumped.  not like its complicated, eh?  and as you can see, screws up the colour coding as well... but WHY!?!?

 

WR!

Link to comment
Share on other sites

The $end error occurs anytime php reaches the end of your file while it is still expecting some php syntax. This can happen for any un-closed php syntax, including a string that is not closed.

 

In your case, it is because the heredoc string is not closed because the ending heredoc tag must start in column 1.

Link to comment
Share on other sites

...mmmmm  nope.  that's not it.  i put the _END right after 'some other stuff':

 

<?php
$fileHandler = fopen("someFile.txt", 'w') or die ("could not create file");
$text = <<<_END
Line1
Line2
Line3
some other stuff_END;
fwrite($fileHandler, $text) or die ("could not write to file");
fclose($fileHandler);
echo "File 'someFile.txt' written successfully";
?>

 

and i still get the error.  any other ideas?

 

WR!

Link to comment
Share on other sites

What is <<<_END?

 

Shouldn't it just be:

 

<?php
$fileHandler = fopen("someFile.txt", 'w') or die ("could not create file");
$text ="Line1\nLine2\nLine3\nsome other stuff" ;
fwrite($fileHandler, $text) or die ("could not write to file");
fclose($fileHandler);
echo "File 'someFile.txt' written successfully";
?>

Link to comment
Share on other sites

...mmmmm  nope.  that's not it.  i put the _END right after 'some other stuff':

 

Wow.

 

	$text = <<<_END
drop some text
and some stuff
plus this stuff
some other stuff

_END;

 

Should have been:

 

	$text = <<<_END
drop some text
and some stuff
plus this stuff
some other stuff

_END;

 

Note the lack of a tab character (or any other space) before _END;

 

This is all very clearly outlined in the PHP manual, see PFMaBiSmAd's latest post.

Link to comment
Share on other sites

okay... i lied.  this DOES NOT work:

 

<?php
$fileHandler = fopen("someFile.txt", 'w') or die ("could not create file");
$text = <<<END
what the heck?
this should work!
_END;
fwrite($fileHandler, $text) or die ("could not write to file");
fclose($fileHandler);
echo "File 'someFile.txt' written successfully";
?>

 

and it should... what's wrong?  :(

 

WR!

Link to comment
Share on other sites

does the text need to be in quotes

 

<?php
$fileHandler = fopen("someFile.txt", 'w') or die ("could not create file");
$text = "<<<END
what the heck?
this should work!
_END";
fwrite($fileHandler, $text) or die ("could not write to file");
fclose($fileHandler);
echo "File 'someFile.txt' written successfully";
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.