If I add some php code to a
.html
.htm
.php
.htm
.php
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:
.php
.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)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).