[SOLVED]Heredoc giving parse errors...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

[SOLVED]Heredoc giving parse errors...

Post by infolock »

Nay, if you are out there, here is a good one for ya. Otherwise, someone else might know the answer to this one.

I've just started trying out heredoc. it works pretty good until you try to tab within it to keep your code straightened up. When I put tabs before my html tags, or the end of my ending of heredoc, i get parse errors every time. i remove the tabs, and it then works fine.

is there something i'm missing here? also, if i replace the tabs with spaces, it works fine, but i really don't want to have to sit and go through every line and add x # of spaces... 8O
Last edited by infolock on Tue Jan 06, 2004 7:18 pm, edited 1 time in total.
onefocus99
Forum Newbie
Posts: 16
Joined: Tue Oct 07, 2003 11:09 pm
Location: Hamilton Ont., Montreal, Chibougamau,... PQ, Victoria BC, now Alberta Canada

Post by onefocus99 »

Depending on what editor you are using
i.e. notetab.com or Macromedia HomeSite 5
both have: Convert Tabs to spaces or spaces to Tabs
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

lol, as soon as i read the title i knew nay's name will be in there somewhere...and its true, wonder why he hast replied yet lol
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

From http://www.php.net/types.string
Warning

It is very important to note that the line with the closing identifier contains no other characters, except possibly a semicolon ( ; ). That means especially that the identifier may not be indented, and there may not be any spaces or tabs after or before the semicolon. It's also important to realize that the first character before the closing identifier must be a newline as defined by your operating system. This is \r on Macintosh for example.

If this rule is broken and the closing identifier is not "clean" then it's not considered to be a closing identifier and PHP will continue looking for one. If in this case a proper closing identifier is not found then a parse error will result with the line number being at the end of the script.
You can't have any spaces on the last line of the heredoc, I think this is your problem.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

My bet is a) onefocus99 version, tabs vs. 4spaced space-indents or b) DuFF's version, malplaced ending (or beginning).

Code: Select all

//works
$str = <<<EOD

    <b>Example of string

EOD;

// does not work
$str = <<<EOD

    <b>Example of string

 EOD; // space before EOD

// nor
$str = <<<EOD

    <b>Example of string EOD;
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

onefocus99 wrote:Depending on what editor you are using
i.e. notetab.com or Macromedia HomeSite 5
both have: Convert Tabs to spaces or spaces to Tabs
nice. it was actually the 4 space issue with Homesite.. at least they offer tab to space heh. only i just don't like having to increase my file size for something that mundane. oh well, i guess i'll have to get used to it til i find a better editor lol..

have tried zend, and most of the others listed on the "what editor do you use", but overall hs has been the best... except for this one small problem with heredoc heh..

thanks again
Post Reply