Home Backend Development PHP Tutorial Things to note when using nowdoc and heredoc in PHP_PHP Tutorial

Things to note when using nowdoc and heredoc in PHP_PHP Tutorial

Jul 13, 2016 am 10:35 AM
php

Finally, I discovered the problem. It turns out that this type of document must be close to the first position of the line at the end, which means that there cannot be a space before EOF. For the sake of code indentation, this problem happened.

Copy code The code is as follows:

$str = <<<'EOD'
Example of string
spanning multiple lines
using nowdoc syntax.
EOD;//EOD must be close to the front, without spaces, and do not miss the ending semicolon;


Attachment: The difference between heredoc and nowdoc

heredoc uses the <<< EOT identifier, while nowdoc uses the <<< 'EOT' identifier. Nowdoc is a new technology introduced in PHP5.3, which contains the syntax of heredoc. , but the content will never be escaped or interpreted in any way. The content is what it is, and PHP-related content will not be parsed
It is recommended to use {$name->change()} for PHP variables in heredoc Enclosed in curly brackets, this can avoid certain ambiguities. If you want to output it as it is, you can use the legendary escape character. The escape character itself can be output using the escape character, that is, this representation method. Braces and the like are all Output needs to be escaped.
In order to ensure that it is usable, it is recommended to use heredoc syntax, which also has escapes. Because the nowdoc syntax was introduced in PHP5.3, many cloud hosting environments may not support it, causing problems.
Finally, heredoc was introduced from PHP 4.0, while nowdoc syntax requires version 5.3. Because heredoc includes the functions of nowdoc, I personally suggest that it is better to use heredoc.

Simply put:
1. Heredoc is dynamic and nowdoc is static
2. Heredoc is similar to multi-line double quotes; newdoc is similar to multi-line single quotes
3. Heredoc is a specialized processing A general processing solution for large strings, and nowdoc is a "highly efficient" static version implemented by PHP to make up for the efficiency problem of dynamic implementation of "heredoc"

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/744336.htmlTechArticleFinally, I discovered the problem. It turns out that at the end of this type of document, it must be close to the first line of the line, that is It is said that there cannot be a space before EOF, but for the sake of code indentation, this problem arises...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

CakePHP Project Configuration

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

CakePHP File upload

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

CakePHP Routing

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP Quick Guide

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

How To Set Up Visual Studio Code (VS Code) for PHP Development

See all articles