Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force Intellij IDEA resolve HTML file as PHP file

I've PHP project, so till now I've been using Intellij IDEA for both Java and PHP without any problem. But now, I've an old PHP project, the project uses HTML files as a PHP files. I mean files with HTML extensions contain PHP code.

However IDEA doesn't recognize them as a PHP file, but when I change extension to PHP it shows everything is fine.

So how can I force IDEA to accept HTML files as PHP files?

Is there any workaround ?

like image 598
Jama A. Avatar asked Feb 17 '23 06:02

Jama A.


1 Answers

Go to File > Settings > File Types (under IDE Settings).

Under Recognized File Types, find PHP files (PHP) (assuming you're using the PHPStorm plugin as I am, if not find where your *.php file extension is registered). If you click on this, then look at Registered Patterns, you will see all file patterns that will be recognized as PHP files. You can click the green + on the right-hand side of the patterns pane, and it will ask for a file-name pattern to recognize as a PHP file. Enter *.html (or something more specific if your HTML files all follow a similar naming pattern). When you hit OK, it will likely say that *.html is already registered with HTML Files. Go ahead and reassign it, then hit OK on the Settings window. Your *.html files will now be recognized as PHP files instead of just HTML files.

I just tested this out in 12.0.4 and it works as I described above.

Do note, however, that this seems to be an IDE-wide setting, and isn't project specific. This unfortunately means that you will have to re-register *.html with HTML Files when opening your other, newer project with the correct file extensions. This is why I suggested a more specific pattern than *.html if your files allow for it, or if you can change the filenames to allow for that.

The most up-to-date way of doing this in IntelliJ can be found here.

like image 173
ajp15243 Avatar answered Mar 05 '23 12:03

ajp15243