简体   繁体   English

Heredoc <<<或<<?

[英]Heredoc <<< or <<?

Well I am wondering what is the right way to do the Heredoc syntax? 好吧,我想知道执行Heredoc语法的正确方法是什么?

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);   
            )
                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 看一下示例2: http//php.net/manual/en/language.types.string.php

It is <<< <<<

You need to put the ending MYSQL; 您需要放入结尾的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; HEREDOC字符串的结尾大部分在换行符之前MYSQL_QUERY; 没有空格 ,因此为MYSQL_QUERY; must be at the start of the line, without whitespace before or after. 必须在行的开头,前后不得有空格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM