简体   繁体   English

如何在PHP字符串和heredoc语法中获得HTML语法高亮?

[英]How do I get HTML syntax highlighting inside PHP strings & heredoc syntax?

I'm using Sublime Text with the Pastels on Dark theme. 我正在使用Sublime Text和Pastel on Dark主题。 My language of choice is PHP. 我选择的语言是PHP。 How can I get HTML syntax highlighting inside PHP strings & heredoc syntax? 如何在PHP字符串和heredoc语法中获得HTML语法高亮?

Name your heredocs after the language you are using. 按照您使用的语言命名您的heredocs。 This will syntax highlight in many text editors, including Sublime Text. 这将在许多文本编辑器中突出显示语法,包括Sublime Text。

For example: 例如:

echo <<<HTML
<!-- put HTML here and it will have syntax highlighting -->
HTML;

Wanted to add this as a comment to Ol' Reliable's answer but I am not allowed yet. 想把这个作为Ol' Reliable答案的评论添加,但我还不允许。

Whilst coding outside and then copying in can be a hassle, for people/editors without syntax highlighting in heredoc, an easy workaround is to temporarily add a closing php tag to the heredoc opening tag: 虽然在外部进行编码然后复制可能很麻烦,对于没有在heredoc中进行语法突出显示的人/编辑,一个简单的解决方法是临时向heredoc开始标记添加一个结束的php标记:

<?php
$myHtmlCode = <<<HTML?>
    <h1>I am Highlighted</h1>
    <p>Remove the closing php tag above to finish editing</p>
HTML;
?>

只需在php之外编写代码,这样您仍然可以看到HTML语法的颜色编码,然后在完成后将该html放入php中。

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

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