Wrong syntax highlighting for PHP file in PHPStorm
Solution 1
Go to Settings|File types and ensure that this particular file name is NOT assigned to non-PHP file type, i.e. Plain Text.
Solution 2
In PHPStorm 10 you have to go to File->Settings and once there Editor->File Type. If plain text probably you will find it on the file type "Text". Check under "registeded patterns" and delete your file from there.
Solution 3
Thanks to @Scotty Waggoner
For some reason the entire filename was added to the Text file type.
Find your file in Settings|FileTypes|Text|RegisteredPatterns and remove it.
Solution 4
Instead of trying to track down which filetype is clashing, the easiest way to fix this is to go to File > Settings
on Windows (or PHPStorm > Preferences
on MacOS), then search for "FILE TYPES".
Go to the troublesome filetype (in this case PHP
) and look for the expected file extension (in this case .php
).
If you see it's missing (as above), then just add it by pressing the + button under "Registered Patterns". Then in the "Add Wildcard" window that opens you would type: *.php
PHPStorm will then tell you that it's mapped to another filetype (the one that's caused this problem), and would you like to move it to this one instead. Simply click "Yes" and it will fix everything. You're all done!
This is much easier than hunting around the other file types for broken one to delete.
Solution 5
I'm not sure if this function is restricted only to phpStorm 9, but there's a simpler solution: if the extension of a file is .php, you can right click on the file in project browsing menu and click "mark as php". That fixed the problem for me.
Related videos on Youtube
chubbyk
Updated on January 26, 2022Comments
-
chubbyk over 2 years
I don't know what happened but syntax highlighting for one php file stopped to working and also icon next to the file has changed. It shows it's text file instead of PHP .
How can I fix that ?
-
dan.codes over 13 yearsThanks this helped me out a lot when one of my files kept showing as a text file.
-
Stuart about 11 yearsIf you have to remove ".php" from another file type, you might to add it back to the PHP type.
-
Scotty Waggoner over 10 yearsFor some reason the entire filename was added to the Text file type. So I had "somefilename.php" as a registered pattern for Text Files. I removed it but didn't think to look there until I saw this post. Thanks!
-
Ronnie Jespersen over 10 yearsThanks! I had same strange behavior. I created a normal file at first by fault. Then tried to rename to *.php and it still was shown as text. Read this comment and looked under Text files. Right enough a single registered pattern was there with the full filename .php - thanks.
-
Destreyf about 10 yearsYou sir... are a saint... this has been driving me up a wall.. For anyone wondering, just look under text files, sure enough at the end, i had like 10 files that had driven me nuts.... WOOT! YOU ROCK!
-
user1669496 over 9 yearsThis recently happened to me as well when I was trying to extract an interface from a class and sure enough, I just found it under the Text Files and remove it and its all good now. What a huge pain that was! It seemed to happen to me when I was trying to extract an interface from a class.
-
Aaronius about 9 yearsSo...how does one accidentally end up adding a file to the Text file type? It's great to know how to fix it once it's there, but how do we avoid it?
-
Koeno almost 9 yearsFor the ones who can't find the option, go to Preferences->Editor->File Types.
-
Chris Laarman over 8 yearsThat only works if you marked it as plain text before
-
drakonli over 8 yearsI assume that's what he did by accident:)
-
Kamil P over 8 yearsI have similar problem. I've created file as txt, but with php extension and PhpStorm recognize this file as txt. If I change name everything is OK, but if I change it back IDE still thinks it's txt file.
-
puppyFlo about 8 yearsThis is great, I have been living with the occasional "glitch" but it turns out that all my twig files with "log" in the title were triggering the log entry in the text file type list - removed that and now i'm being highlighted again. Just in case the phpstorm team see this, your patterns aren't applied in the normal way - general.log.twig matches *.log and that's just not right.. Anyway, thank you!
-
Agu V almost 8 yearsI had a file for months without the proper file type. Thank you!
-
David J Eddy almost 8 yearsSomeone give @Alexey Gopachenko a cookie, perfect answer.
-
Dimitry K about 7 yearsTIP: you can add
composer.lock
as file pattern for "JSON File type" which will enable highlighting and folding in the editor :) -
Muzafar Ali almost 7 yearsFor those who still can't find the option goto
Preferences > Editor > File Types
, fromRecognized File Types
selectText
and remove your file fromRegistered Patterns
section below! -
phpguru over 6 yearsWhoa, my file was listed! Crazy. I wouldn't have thought to check there as I thought the extensions were wildcard patterns only in this list. Thanks - that worked for me!
-
Robin Layfield about 6 yearsMark as Plain Text. You can also right-click on the file and select "Mark as PHP" or "Mark as plain-text" to fix incorrect syntax highlighting.
-
exts almost 6 yearsThank you for this, jesus i apparently accidentally added the full filename & type from a menu that I don't remember clicking.
-
Chris almost 6 yearsWow thank you! I had files that didn't match any defined type (icon was a text file with a cross in the corner, whatever that means) so couldn't find them. This worked!
-
Adriana Hernández about 5 yearsOMG thank you very much. This was a big problem for me, and now is not a problem anymore
-
Chris about 5 yearsHere's what you probably did, created a new file without an extension, when the window popped up asking what file type this was, you tried to add ".php" to the end of the filename at the top of the window. This doesn't rename the file though as you might think it would, rather it adds your <filename>.php to the default filetype (text) for a file with no extension. I know because, I just did it and found this thread to fix it.
-
Samuël Visser almost 5 yearsYes had the exact same problem as Chris, this finally fixed it for me! Thanks!