PHP 中的空格导致无意义的错误?
我正在编辑 WordPress 主题的functions.php 文件,每当我编辑它时,即使编辑添加单个空格,服务器也会返回
错误:
Parse error: syntax error, unexpected '}' in /theme/functions.php on line 1
这是我添加单个空格的位置:
<?php load_theme_textdomain('theme', get_template_directory() . '/languages');
<— I added a single space here
和之后一切都会消亡。这不是一个一致的错误,因为在我用备份的文件替换整个functions.php 文件本身后它就消失了。仅当我编辑文件时,它才会被复制,也就是说,即使只有单个空白字符也会出现这种情况。我使用 NetBeans 和 CuteFTP 编辑然后上传文件。
到底是怎么回事?! 这肯定与某种文件质量本身有关,因为从代码的角度来看,代码是完全相同的......或者可能是我的服务器。
解决方案:
Netbeans 默认为每个项目使用特定的文件编码。外部文件可能具有不同的编码,这可能会导致问题。将外部文件的内容复制到您通过 Netbeans 创建的新空白文件中。
I'm editing the functions.php file of a WordPress theme and whenever I edit it, even when the edit is adding a single space the server returns
error:
Parse error: syntax error, unexpected '}' in /theme/functions.php on line 1
This is where I add the single space:
<?php load_theme_textdomain('theme', get_template_directory() . '/languages');
<— I added a single space here
and everything dies after that. This is not a consistent error, as it goes away after I replace the whole functions.php file itself with a backed up one. It only is replicated when I edit the file, that is, as presented even with single white-space character. I'm using NetBeans and CuteFTP to edit then upload the files.
What is going on?!
This must have to do with some kind of file quality itself, since from a code standpoint the code is exactly the same...or maybe my server.
Solution:
Netbeans defaults to a specific file encoding per project. Foreign files may have a different encoding which may cause problems. Cody the foreign file's contents to a new blank file which you created via Netbeans.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能是编码错误。也许当您尝试编辑文件时,您的文本编辑器在顶部包含 UTF-8 BOM。
编辑
刚刚在Notepad++中找到了保存为没有BOM的UTF-8的说明:
(来源:http: //www.phpbb.com/community/viewtopic.php?f=66&t=1584655#p9490925,底部第五个答案)
但是您需要设置的编码实际上取决于原始文件。如果不是 UTF-8,则应保留原始编码(Latin 1 或其他编码)。
It could be an encoding error. Maybe when you try to edit the file your text editor is including a UTF-8 BOM at the top.
EDIT
Just found instructions for saving as UTF-8 without BOM in Notepad++:
(Source: http://www.phpbb.com/community/viewtopic.php?f=66&t=1584655#p9490925, 5th answer from the bottom)
But the encoding you need to set really depends on the original file. If it's not UTF-8, you should keep the original encoding (Latin 1 or whatever).
您是否将其包含在正确的位置?请参阅http://codex.wordpress.org/Function_Reference/load_theme_textdomain
Are you including it in the right place? See http://codex.wordpress.org/Function_Reference/load_theme_textdomain