Well I am wondering what is the right way to do the Heredoc syntax?
In my code editor, which is 'e-text editor' doing <<<
totally throws off the syntax highlighting.
and doing << instead doesn't.
code:
private function buildDB() {
// build database
$sql = <<<MySQL_QUERY
CREATE TABLE IF NOT EXISTS testDB (
title VARCHAR(150),
bodytext TEXT,
created VARCHAR(100);
开发者_Go百科 )
MYSQL_QUERY;
return mysql_query($sql);
}
Which is the right way? I am still very noobish so no idea.
or maybe I shouldn't rely on syntax highlighting eh? :/
Take a look at example 2: http://php.net/manual/en/language.types.string.php
It is <<<
You need to put the ending MYSQL;
on the beginning of the line without any whitespace. That's why your editor won't highlight it correctly.
The closing of the HEREDOC string most be on a new line without spaces before it, so MYSQL_QUERY;
must be at the start of the line, without whitespace before or after.
精彩评论