Wrong syntax highlighting for PHP file in PHPStorm

51,809

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).

enter image description here

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

enter image description here

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.

Share:
51,809

Related videos on Youtube

chubbyk
Author by

chubbyk

Updated on January 26, 2022

Comments

  • chubbyk
    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
    dan.codes over 13 years
    Thanks this helped me out a lot when one of my files kept showing as a text file.
  • Stuart
    Stuart about 11 years
    If you have to remove ".php" from another file type, you might to add it back to the PHP type.
  • Scotty Waggoner
    Scotty Waggoner over 10 years
    For 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
    Ronnie Jespersen over 10 years
    Thanks! 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
    Destreyf about 10 years
    You 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
    user1669496 over 9 years
    This 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
    Aaronius about 9 years
    So...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
    Koeno almost 9 years
    For the ones who can't find the option, go to Preferences->Editor->File Types.
  • Chris Laarman
    Chris Laarman over 8 years
    That only works if you marked it as plain text before
  • drakonli
    drakonli over 8 years
    I assume that's what he did by accident:)
  • Kamil P
    Kamil P over 8 years
    I 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
    puppyFlo about 8 years
    This 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
    Agu V almost 8 years
    I had a file for months without the proper file type. Thank you!
  • David J Eddy
    David J Eddy almost 8 years
    Someone give @Alexey Gopachenko a cookie, perfect answer.
  • Dimitry K
    Dimitry K about 7 years
    TIP: you can add composer.lock as file pattern for "JSON File type" which will enable highlighting and folding in the editor :)
  • Muzafar Ali
    Muzafar Ali almost 7 years
    For those who still can't find the option goto Preferences > Editor > File Types, from Recognized File Types select Text and remove your file from Registered Patterns section below!
  • phpguru
    phpguru over 6 years
    Whoa, 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
    Robin Layfield about 6 years
    Mark 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
    exts almost 6 years
    Thank you for this, jesus i apparently accidentally added the full filename & type from a menu that I don't remember clicking.
  • Chris
    Chris almost 6 years
    Wow 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
    Adriana Hernández about 5 years
    OMG thank you very much. This was a big problem for me, and now is not a problem anymore
  • Chris
    Chris about 5 years
    Here'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
    Samuël Visser almost 5 years
    Yes had the exact same problem as Chris, this finally fixed it for me! Thanks!