note 105835 added to language.types.string

From: Date: Mon, 19 Sep 2011 08:38:28 +0000
Subject: note 105835 added to language.types.string
Groups: php.notes 
Request: Send a blank email to php-notes+get-183269@lists.php.net to get a copy of this message
Actually, HEREDOC works precisely as documented, with nothing hidden at all. It's just that it's one of those things which isn't entirely intuitive to grasp. A HEREDOC block has to start with the delimiter followed by a newline, and end with a newline followed by the delimiter. That means that the leading and trailing newlines are part of the syntax, not a part of the block. So this <?php $foo = <<<EOF this is a block EOF; ?> is equivalent to this <?php $foo = "this is a block"; ?> or this <?php $foo = "this\nis\na\nblock"; ?> but not this: <?php $foo = " this is a block "; ?> or this <?php $foo = "\nthis\nis\na\nblock\n"; ?> Viewing it with the syntax highlighting switched on helps to make the difference clearer. ---- Server IP: 87.124.126.105 Probable Submitter: 217.10.137.146 (proxied: 217.10.137.146) ---- Manual Page -- http://www.php.net/manual/en/language.types.string.php Edit -- https://master.php.net/note/edit/105835 Del: integrated -- https://master.php.net/note/delete/105835/integrated Del: useless -- https://master.php.net/note/delete/105835/useless Del: bad code -- https://master.php.net/note/delete/105835/bad+code Del: spam -- https://master.php.net/note/delete/105835/spam Del: non-english -- https://master.php.net/note/delete/105835/non-english Del: in docs -- https://master.php.net/note/delete/105835/in+docs Del: other reasons-- https://master.php.net/note/delete/105835 Reject -- https://master.php.net/note/reject/105835 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#183269) next »