If I add some php code to a
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.
.html files are associated with "HTML Files" file type.
Few possible solutions:
.phtmlfile 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)
.htm (or whatever else extension you want) with "PHP File" file type.
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).