Search code examples
syntax-highlightingphpstorm

PHPStorm: Syntax Highlighting for PHP code inside XML tags


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

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>

Solution

  • 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).

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

    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 -- find such files (or whole folder) and assign XML in 2nd column.

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


    Official manual: http://confluence.jetbrains.com/display/PhpStorm/Syntax+highlighting+of+PHP+inside+JavaScript+%28and+other+languages%29