0

Possible Duplicate:
What's this kind of syntax in PHP?
What is the name for the “<<<” operator?

In a example (specifically http://code.google.com/p/php-pdo-wrapper-class/) I've seen this:

$sql = <<<SQL
CREATE TABLE mytable (
    ID int(11) NOT NULL AUTO_INCREMENT,
    FName varchar(50) NOT NULL,
    LName varchar(50) NOT NULL,
    Age int(11) NOT NULL,
    Gender enum('male','female') NOT NULL,
    PRIMARY KEY (ID)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ;
SQL;
$db->run($sql);

what is this syntax (I don't use php that much). I can't find anything on google because it skips the <<< thingy.

Community
  • 1
  • 1
gotch4
  • 13,093
  • 29
  • 107
  • 170
  • 2
    It's called [heredoc syntax](http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc). – Josh Mar 05 '12 at 17:50
  • I've never seen that either but I'm going to start using it! If it is anything like bash or many other scripting languages, it means "Read standard input until you see this marker. The marker in this case is the string "SQL". So it starts reading all those lines between "<< – Resorath Mar 05 '12 at 17:51

3 Answers3

1

It's the Herehoc syntax, an alternative way to put together large strings. It's like a double quoted string in that variables are evaluated, but you don't have to escape any characters. It's great for HTML, what with all the quotes you typically have. Learn more: http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

Surreal Dreams
  • 26,055
  • 3
  • 46
  • 61
1

It's called HEREDOC. See the manual entry.

It allows you to escape long text sequences to make a variable assignment.

Ryan
  • 26,884
  • 9
  • 56
  • 83
0

It's called heredoc syntax.

mbosecke
  • 842
  • 10
  • 22