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

大憨熊 提交于 2020-02-23 09:27:09

问题


I'm using Sublime Text with the Pastels on Dark theme. My language of choice is PHP. How can I get HTML syntax highlighting inside PHP strings & heredoc syntax?


回答1:


Name your heredocs after the language you are using. This will syntax highlight in many text editors, including Sublime Text.

For example:

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



回答2:


Wanted to add this as a comment to Ol' Reliable's answer but I am not allowed yet.

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:

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



回答3:


Just code outside of php so you can still see the HTML syntax color-coded, and then put that html inside the php once you are done.



来源:https://stackoverflow.com/questions/18337477/how-do-i-get-html-syntax-highlighting-inside-php-strings-heredoc-syntax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!