PHPStorm 中 PHP 文件的语法高亮错误
我不知道发生了什么,但一个 php 文件的语法突出显示停止工作,并且文件旁边的图标也发生了变化。它显示它是文本文件而不是 PHP 。
我该如何解决这个问题?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
转到“设置”|“文件类型”并确保该特定文件名未分配给非 PHP 文件类型(即纯文本)。
Go to Settings|File types and ensure that this particular file name is NOT assigned to non-PHP file type, i.e. Plain Text.
在 PHPStorm 10 中,您必须转到“文件”->“设置”,然后进入“编辑器”->“文件类型”。如果是纯文本,您可能会在文件类型“文本”中找到它。检查“注册模式”并从那里删除您的文件。
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.
感谢@Scotty Wagoner
在“设置|文件类型|文本|RegisteredPatterns”中找到您的文件并将其删除。
Thanks to @Scotty Waggoner
Find your file in Settings|FileTypes|Text|RegisteredPatterns and remove it.
解决此问题的最简单方法是转到
File > ,而不是尝试找出发生冲突的文件类型。 Windows 上的设置
(或 MacOS 上的PHPStorm > 首选项
),然后搜索“文件类型”。转到有问题的文件类型(在本例中为
PHP
)并查找所需的文件扩展名(在本例中为.php
)。如果您发现它丢失了(如上所述),则只需按“注册模式”下的 + 按钮即可添加它。然后在打开的“添加通配符”窗口中输入:
*.php
PHPStorm 会告诉您它已映射到另一种文件类型(导致此问题的文件类型) ),您想将其移至此吗?只需单击“是”即可解决所有问题。你都完成了!
这比寻找其他文件类型来删除损坏的文件要容易得多。
Instead of trying to track down which filetype is clashing, the easiest way to fix this is to go to
File > Settings
on Windows (orPHPStorm > 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.
我不确定这个功能是否仅限于 phpStorm 9,但有一个更简单的解决方案:如果文件的扩展名是 .php,您可以在项目浏览菜单中右键单击该文件,然后单击“标记为 php”。这解决了我的问题。
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.
在 MacOS 上的 PHPStorm 2019.1 中:
PhpStorm >首选项>编辑>文件类型>可识别的文件类型> Text
从
Registered Patterns
中删除包含您的文件名的条目,即删除File.php
(如果File.php
是)有问题的文件。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 removeFile.php
ifFile.php
is the problematic file.右键单击该文件->覆盖文件类型 ->设置为 PHP
Right click on the file -> Override file type -> Set as PHP
这个问题很旧,但我为无法解决此问题的人回答:
您可能删除了 PHP start(
) 或 end (
?>
) 标签,因此以纯文本显示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 会询问您是否要自动检测语法突出显示的内容。这似乎不适用于 php 内容。如果您稍后添加扩展名(此处为 .php),您现在会期望看到正确的突出显示,但由于列表为“按内容自动检测文件类型”,它将切换突出显示
修复:检查是否没有正式突出显示文件已注册为错误的文件类型
转到文件 ->设置 (Windows) 或 PHPStorm ->然后,在首选项 (MacO) 中搜索“文件类型”或导航至编辑器 ->文件类型
查找“文本”和“按内容自动检测文件类型”,并确保您的文件未在“文件名模式”下列出
预防:将 .php 扩展名添加到“文件名模式”中设置
按照上述修复中的说明进行导航,并在“文件名模式”下添加“*.php”。如果您现在创建一个没有扩展名的文件,将其标记为“自动检测”并稍后添加扩展名,它将被正确识别为 PHP 文件
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
对我来说,问题是我禁用了对文件的 PHP 检查:
重新启用“所有问题”后,文件按应有的方式显示。
For me the issue was I had disable PHP inspections on the file:
After re-enabling "All Problems" the file appeared as it should.