PHPStorm 中 PHP 文件的语法高亮错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4306182/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Wrong syntax highlighting for PHP file in PHPStorm
提问by chubbyk
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 .
我不知道发生了什么,但是一个 php 文件的语法高亮显示停止工作,并且文件旁边的图标也发生了变化。它显示它的文本文件而不是 PHP 。
How can I fix that ?
我该如何解决?
回答by Alexey Gopachenko
Go to Settings|File types and ensure that this particular file name is NOT assigned to non-PHP file type, i.e. Plain Text.
转到设置|文件类型并确保此特定文件名未分配给非 PHP 文件类型,即纯文本。
回答by Rodrigo Lopez Guerra
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.
在 PHPStorm 10 中,您必须转到“文件”->“设置”,然后转到“编辑器”->“文件类型”。如果是纯文本,您可能会在文件类型“文本”中找到它。检查“注册模式”并从那里删除您的文件。
回答by hhsadiq
Thanks to @Scotty Waggoner
感谢@Scotty Wagoner
For some reason the entire filename was added to the Text file type.
出于某种原因,整个文件名被添加到文本文件类型中。
Find your file in Settings|FileTypes|Text|RegisteredPatterns and remove it.
在 Settings|FileTypes|Text|RegisteredPatterns 中找到您的文件并将其删除。
回答by drakonli
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.
我不确定这个功能是否仅限于 phpStorm 9,但有一个更简单的解决方案:如果文件的扩展名为 .php,您可以在项目浏览菜单中右键单击该文件,然后单击“标记为 php”。那为我解决了问题。
回答by Chuck Le Butt
The easiest way to fix this is to go to File > Settings
on Windows (or PHPStorm > Preferences
on MacOS), then search for "FILE TYPES".
解决此问题的最简单方法是转到File > Settings
Windows(或PHPStorm > Preferences
MacOS),然后搜索“文件类型”。
Scroll down to the troublesome filetype (in this case PHP).
向下滚动到麻烦的文件类型(在本例中为 PHP)。
Then look for the expected file extension (in this case .php).
然后查找预期的文件扩展名(在本例中为 .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
如果您发现它丢失(如上),则只需按“注册模式”下的 + 按钮即可添加它。然后在打开的“添加通配符”窗口中输入:*.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!
PHPStorm 然后会告诉您它已映射到另一种文件类型(导致此问题的文件类型),并且您是否希望将其移动到该文件类型。只需单击“是”,它就会解决所有问题。你都完成了!
This is much easier than hunting around the other file types for broken one to delete.
这比寻找其他文件类型以删除损坏的文件要容易得多。
回答by Nicholas Betsworth
In PHPStorm 2019.1 on MacOS:
在 MacOS 上的 PHPStorm 2019.1 中:
PhpStorm > Preferences > Editor > File Types > Recognized File Types > Text
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.
删除从入门Registered Patterns
包含文件名,即删除File.php
,如果File.php
是有问题的文件。
回答by sidoco
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
您可能删除了 PHP 开始( <? php
) 或结束 ( ?>
) 标记之一,因此以纯文本形式显示