heredoc problem

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
omidkamangar
Forum Newbie
Posts: 16
Joined: Sun Jul 30, 2006 2:51 pm

heredoc problem

Post by omidkamangar »

Hi ,
As I am new to PHP programming I have got a problem with heredoc style:
When I write a piece of code like this :

Code: Select all

$str = <<<BOT
    This is  text 
    in heredoc notation
    BOT;
    //-------------

    echo $str;
I get an error message.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

Have you looked at this? (not trying to be condescending, just wondering)

http://us2.php.net/manual/en/language.t ... ax.heredoc
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: heredoc problem

Post by Christopher »

omidkamangar wrote:I get an error message.
What is the error message?
(#10850)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

"BOT" must be the first characters on the line it's on. No whitespace or anything can lead it. Some systems have problems if there is a space after the declaration too: "<<<BOT"
omidkamangar
Forum Newbie
Posts: 16
Joined: Sun Jul 30, 2006 2:51 pm

Post by omidkamangar »

This is the error message I get :

Code: Select all

Parse error: syntax error, unexpected $end in E:\xampp\htdocs\shahoo\test.php
Last edited by omidkamangar on Sat Aug 05, 2006 10:12 am, edited 1 time in total.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: heredoc problem

Post by RobertGonzalez »

omidkamangar wrote:Hi ,
As I am new to PHP programming I have got a problem with heredoc style:
When I write a piece of code like this :

Code: Select all

$str = <<<BOT
    This is  text 
    in heredoc notation
    BOT;
    //-------------

    echo $str;
I get an error message.
It needs to be...

Code: Select all

$str = <<<BOT
    This is  text 
    in heredoc notation
BOT;

    echo $str;
See how BOT is all the way to the left and is the only thing on its line? That is how heredoc works.
Post Reply