Php inspections on .htm file

Hello everyone, I did some configurations on my apache so .htm files will be treated as .php files, My problem is that when phpstorm open .htm/.html files it uses the html Inspections even if i got php code inside, So what i was trying to do is to set phpstorm to use both inspections (HTML Inspections and Php Inspections) on .htm/.html, For example when phpstorm open .php files it uses both HTML inspections and Php inspections, What i want to do it to enable phpstorm to use both inspection also on .htm/.html files, Thank you all and have a nice day.

Comment actions Permalink

Hi there,

You need to tell PhpStorm to treat .htm files as PHP files. For that:

  • Settings | File Types
  • PHP files
  • Add *.htm pattern there (it will ask you to remove it first from "HTML files" -- just agree)

Please note: The "File Types" is IDE-wide setting and will affect ALL projects.

In my opinion, the better approach here would be:

  1. Use different file extension instead of *.htm -- for example *.phtm (you will need to alter your Apache config for this -- very minor change)
  2. Use complex extension: *.php.htm or *.htm.php -- this would allow to treat *.htm as HTML files and *.php.htm as PHP files (no changes on Apache side required)
Comment actions Permalink

Thank you Andriy, Also for your solutions, Have a nice day.


Please sign in to leave a comment.