本文介绍了与HTML混合时,PhpStorm不会突出显示.php文件中的PHP代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在PHPStorm中遇到了一个问题,当它与HTML代码混合在一起时,它不会在PHP文件中突出显示PHP代码(但会智能化它)。



截图(点击放大):





如果我无效缓存/重新启动,它会在几秒钟内显示正确的高亮显示。但是,在计算之后,它将返回到不突出显示的状态。



是否有这样的设置?或者它只是一个普通的错误?



我已经阅读过关于语言注入的内容,但这看起来并不是它的地方,因为它已经是.php文件了,PHP是而不是注射语言列表。



相关代码:

  <?php 
$ works =yes;
?>

< html>
< body>

< script>
var shouldStillWorkAfterThis = true;
< / script>

<?php
$ works =yes;
?>

< table>
< tr>
< td><?php $ works =yes; ?>< / TD>
< / tr>
< / table>

<?php
if($ works){
?>
< table>
< tr>
< td><?= $ works?>< / td>
< / tr>
< / table>
<?php $ thisShouldToo = true; ?>
<?php}?>

< div id =someclass>
< header>
< div class =someotherclass>
< div class =andanextraclass>
<! - 包含档案 - >
<?php include('somefile.php');?>
<?php
$ anythingHereIsNowBroken = true;
?>
< / div>
< / div>
< / header>
< / div>

< / body>
< / html>

语言注入设置:



我在MacOSX 10.9.5上使用PhpStorm 8.0.3。

解决方案

根据设置(Mac上的首选项)的屏幕截图|编辑|语言注入



请从底部删除第三种语言注入规则(div在范围列中有IDE)。



该规则将HTML注入 div 标签,告诉IDE要处理所有其他代码(甚至是PHP)在HTML /纯文本等标签内。


I am having a problem in PHPStorm where it won't highlight PHP code (but will intellisense it) inside a .php file when it's mixed with HTML code.

Screenshot (click to enlarge):

If I invalidate cache/restart, it will, for a few seconds, show the correct highlighting. However, after it "calculates", it will return to not highlighting it.

Is there a setting for this? Or is it just a plain bug?

I have read about language injections, but this does not seem like the place for it since it's a .php file already and PHP is not on the list of injectable languages.

Relevant code:

<?php
$works = "yes";
?>

<html>
<body>

<script>
    var shouldStillWorkAfterThis = true;
</script>

<?php
$works = "yes";
?>

<table>
    <tr>
        <td><?php $works = "yes"; ?></td>
    </tr>
</table>

<!-- lets try split syntax -->
<?php
if ($works) {
    ?>
    <table>
        <tr>
            <td><?= $works ?></td>
        </tr>
    </table>
    <?php $thisShouldToo = true; ?>
<?php } ?>

<!-- lets break it -->
<div id="someclass">
    <header>
        <div class="someotherclass">
            <div class="andanextraclass">
                <!-- include a file-->
                <?php include('somefile.php');?>
                <?php
                    $anythingHereIsNowBroken = true;
                ?>
            </div>
        </div>
    </header>
</div>

</body>
</html>

Language Injections Settings:

I am using PhpStorm 8.0.3 on MacOSX 10.9.5.

解决方案

Based on your screenshot of Settings (Preferences on Mac) | Editor | Language Injections.

Please delete 3rd language injection rule from the bottom (the one for "div" -- that has "IDE" in Scope column).

That rule injects HTML into div tag which tells IDE to treat all other code (even PHP) inside such tag as HTML/plain text.

这篇关于与HTML混合时,PhpStorm不会突出显示.php文件中的PHP代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 10:25