Moshe Moshe - 5 months ago 42
HTML Question

PHP Code Style in .htm File in PhpStorm

If I add some php code to a

file in PhpStorm, the code style for that bit of php code is NOT the same as in

For instance, here is the same code in two different file formats:

enter image description here

enter image description here

How can I get the php code segment inside of the
to look like it does in a


The reason I want php code styling within an htm file is because I am using October CMS. October CMS uses a .htm file extension which is divided into three section. One of those section is for php code. What I want to know is how can I get the php content code which resides in the htm file to use my php code styles within PhpStorm.


In order for PhpStorm to recognize and highlight PHP code in any file such file MUST be associated with "PHP File" file type and have PHP icon next to file name.

By default .htm/.html files are associated with "HTML Files" file type.

Few possible solutions:

  1. Change extension of existing file to be .php
  2. Use .phtml file extension -- which is commonly used extension for such cases (in general denotes that this file is a "template" -- a HTML file mixed with PHP instructions)
  3. Associate .htm (or whatever else extension you want) with "PHP File" file type.

    For that: Settings/Preferences | Editor | File Types -- find "PHP File" and add appropriate pattern (e.g. *.htm). IDE will ask if you want to remove such pattern from existing/default "HTML File" to this "PHP File".

    Possible downside: some HTML inspections may not be triggered (relaxed) in PHP file.

    NOTE: Such association is IDE-wide and affects ALL projects.

The best/most neutral solution overall is #2 -- use dedicated file extension for such files (*.phtml is a most commonly used).