本文介绍了PHPStorm:XML标记内的PHP代码语法高亮显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何方法可以使PHPStorm将语法高亮显示应用于XML文件中的标记内的PHP代码?

Is there any way to make PHPStorm apply syntax highlighting to PHP code inside a tag in an XML file?

我正在处理OpenCart项目,并且正在使用 Vqmod 我在XML文件中编写PHP代码.例如:

I'm working on an OpenCart project and I'm using Vqmod, which requires that I write PHP code in an XML file. For example:

<operation>
    <search position="replace"><![CDATA[
        <?php echo "123"; ?>
    ]]></search>

    <add><![CDATA[
        <?php echo "xyz"; ?>
    ]]></add>

</operation>

推荐答案

1) Settings | File Types-将*.xml(或您认为更合适的任何文件名模式)分配给条目(您可能需要先将其从"XML文件"中删除).

1) Settings | File Types -- assign *.xml (or whatever file name pattern you think is more appropriate) to PHP files entry (you may need to remove it from "XML files" first).

这将告诉PhpStorm 处理PHP之类的文件(这是获得PHP支持的唯一方法).

This will tell PhpStorm to treat such files as PHP (it's the only way to have PHP support).

可能的不利方面-这是IDE范围的设置,将影响所有项目中的所有此类文件.因此-如果您可以使用某些唯一的方式来命名此类文件(例如,双扩展名:*.php.xml*.xml.php;唯一的扩展名:*.pxml;唯一的文件名结尾:*layout.xml),则可以这样做.

The possible negative side -- it's an IDE-wide setting and will affect ALL such files in ALL projects. Therefore -- if you can name such files in some unique way (e.g. double extension: *.php.xml or *.xml.php; unique extension: *.pxml; unique file name ending: *layout.xml) then do it.

2) Settings | Template Data Languages-查找此类文件(或整个文件夹)并在第二列中分配 XML .

2) Settings | Template Data Languages -- find such files (or whole folder) and assign XML in 2nd column.

这将告诉PhpStorm将此类文件视为带有XML的PHP​​",而不是默认的带有HTML的PHP​​".

This will tell PhpStorm to treat such files as "PHP with XML" instead of default "PHP with HTML".

官方手册: http://confluence.jetbrains.com/display/PhpStorm/语法+ highlighting + of + PHP + inside + JavaScript +%28and + other +语言%29

这篇关于PHPStorm:XML标记内的PHP代码语法高亮显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 20:08