HEREDOC interfering with code indentation

后端 未结 6 1079
没有蜡笔的小新
没有蜡笔的小新 2020-12-03 10:48

I like the HEREDOC syntax, e.g. for edge cases of generated HTML that are not worth putting into a template.

The only thing that annoys me about it, though, is that

6条回答
  •  Happy的楠姐
    2020-12-03 11:23

    I just discovered an odd workaround for anyone still wondering how to do this. Indent your first line that starts the HEREDOC. Your second line, which is the first line of the HEREDOC, has to have no whitespace, so leave it as a blank line. Start a new line after that, indent it and write your code. Then complete the HEREDOC, again with no white space. Visually you'll get all of your code indented except for the completion of the HEREDOC. Highlight + TAB still an issue, but at least the code is more readable within control loops, etc, now.

               $html = <<< HTML                    //indented line
                                                   //leave this line empty
               
    //indented line
    $variable
    //indented line
    //indented line HTML; //no white space, not indented

提交回复
热议问题