开发者

EOD not ending?

EOD not ending?

<?php

// Page class

class Page {

// Declare a class member variable
var $page;
var $title;
var $year;
var $copyright;

// The Constructor function
function Page($title, $year, $copyright){
// Assign values to member variables
$this->page = '';
$this->title = $title;
$this->year = $year;
$this->copyright =开发者_如何学编程 $copyright;

// Call the addHeader() method
$this->addHeader();
}

// Generates the top of the page
function addHeader(){
$this->page .= <<<EOD
                <html>
                <head>
                <title>$this->title</title>
                </head>
                <body>
                <h1 align="center">$this->title</h1>
                </body>
                EOD;
    }
}




?>


The EOD; must be at the very beginning of the line.. no white space or anything before it

Quote from the manual:

Warning
It is very important to note that the line with the closing identifier must contain 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 before or after the semicolon. It's also important to realize that the first character before the closing identifier must be a newline as defined by the local operating system. This is \n on UNIX systems, including Mac OS X. The closing delimiter (possibly followed by a semicolon) must also be followed by a newline.

If this rule is broken and the closing identifier is not "clean", it will not be considered a closing identifier, and PHP will continue looking for one. If a proper closing identifier is not found before the end of the current file, a parse error will result at the last line.


You shouldn't indent the heredoc marker, it isn't recognized with the leading spaces or tabs.


Hard to say the actual problem but take a look at heredoc docs: http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜