【问题标题】:PhpStorm not highlighting PHP code inside a .php file when mixed with HTML与 HTML 混合时,PhpStorm 不会突出显示 .php 文件中的 PHP 代码
【发布时间】:2015-05-30 08:33:14
【问题描述】:

我在 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>

<!-- 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>

语言注入设置:

我在 MacOSX 10.9.5 上使用 PhpStorm 8.0.3。

【问题讨论】:

标签: php html phpstorm


【解决方案1】:

根据你对Settings (Preferences on Mac) | Editor | Language Injections的截图。

请从底部删除第 3 种语言注入规则(用于“div”的规则 -- 在 Scope 列中有“IDE”)。

该规则将 HTML 注入到 div 标记中,这告诉 IDE 将此类标记内的所有其他代码(甚至 PHP)视为 HTML/纯文本。

【讨论】:

  • 这正是问题所在。谢谢 :) 这是之后的样子:puu.sh/i5L8D/d8cffe4471.png
  • 非常感谢!也帮助了我:-)
  • 完美解决方案。经过一年多的回答,它解决了我的问题。我在 Windows 中使用 PHPStorm 2016.3。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多