English 中文(简体)
Wrong syntax highlighting for PHP file in PHPStorm
原标题:

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 ?

问题回答

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

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.

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.

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.

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.

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.

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

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

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





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签