156

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 ?

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
chubbyk
  • 6,212
  • 13
  • 53
  • 67

10 Answers10

353

Go to Settings|File types and ensure that this particular file name is NOT assigned to non-PHP file type, i.e. Plain Text.

Alexey Gopachenko
  • 7,458
  • 3
  • 27
  • 25
  • 5
    Thanks this helped me out a lot when one of my files kept showing as a text file. – dan.codes Jan 23 '11 at 15:53
  • If you have to remove ".php" from another file type, you might to add it back to the PHP type. – Stuart Feb 09 '13 at 02:39
  • 95
    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! – Scotty Waggoner Sep 11 '13 at 07:50
  • 4
    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. – Ronnie Jespersen Jan 09 '14 at 22:29
  • 4
    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! – Destreyf Apr 29 '14 at 01:41
  • 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. – user1669496 Jan 21 '15 at 22:25
  • 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? – Aaronius Apr 03 '15 at 17:17
  • 25
    For the ones who can't find the option, go to Preferences->Editor->File Types. – Koeno May 20 '15 at 09:26
  • 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. – Kamil P Jan 04 '16 at 14:26
  • 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! – puppyFlo Feb 16 '16 at 08:33
  • I had a file for months without the proper file type. Thank you! – Agu V May 23 '16 at 19:43
  • Someone give @Alexey Gopachenko a cookie, perfect answer. – David J Eddy May 31 '16 at 15:17
  • TIP: you can add `composer.lock` as file pattern for "JSON File type" which will enable highlighting and folding in the editor :) – Dimitry K Mar 30 '17 at 18:46
  • 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! – Muzafar Ali May 08 '17 at 09:41
  • 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. – Robin Layfield Feb 05 '18 at 14:09
  • OMG thank you very much. This was a big problem for me, and now is not a problem anymore – Adriana Hernández Feb 13 '19 at 20:35
54

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.

  • 1
    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! – phpguru Aug 14 '17 at 19:29
21

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.

hhsadiq
  • 2,871
  • 1
  • 25
  • 39
  • 1
    Thank you for this, jesus i apparently accidentally added the full filename & type from a menu that I don't remember clicking. – exts May 09 '18 at 20:04
  • 4
    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 .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. – Chris Feb 28 '19 at 10:31
20

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.

Chuck Le Butt
  • 47,570
  • 62
  • 203
  • 289
18

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.

drakonli
  • 2,304
  • 23
  • 29
10

In PHPStorm 2019.1 on MacOS:

PhpStorm > Preferences > Editor > File Types > Recognized File Types > Text

Remove the entry from Registered Patterns which contains your file-name, i.e remove File.php if File.php is the problematic file.

Nicholas Betsworth
  • 1,707
  • 19
  • 24
3

Right click on the file -> Override file type -> Set as PHP

1

This question is old but I answer for someone that couldn't solve this:

You may have removed one of the PHP start(<?php) or end (?>) tags and is therefore displayed in plain text

Chuck Le Butt
  • 47,570
  • 62
  • 203
  • 289
sidoco
  • 99
  • 10
1

Same problem but my file wasn't in "Text" but "File type auto-detected by file content"

PhpStorm > Preferences > Editor > File Types > Recognized File Types > File type auto-detected by file content

Tib
  • 2,553
  • 1
  • 27
  • 46
0

The most voted Answer is not complete.

Source of this problem

If you create a new file without adding a file extension, PHPStorm asks you if you want to auto-detect the content for syntax highlighting. It seems like this is not working for php content. If you add the extension (here .php) later, you would expect to now see the proper highlighting but because of the listing as "Auto-detect file type by content" it will switch the highlighting

Fix: Check if the not formally highlighted File is registered as wrong file type

Go to File -> Settings (Windows) or PHPStorm -> Preferences (MacOs) then search for "File Types" or navigate to Editor -> File Types

Look up "Text" and "Auto-detect file type by content" and be sure your file is not listed under "File name patterns"

Prevention: Add the .php Extension to the "File name Patterns" in the Settings

Navigate as stated in the fix above and add "*.php" under "File name patterns". If you now create a file without extension, mark it as "auto-detect" and add the extension later, it will be properly recognized as PHP-File

JanO
  • 21
  • 2