谢邦#!在Ubuntu中无法识别,在Windows7中创建的文件|编码故障排除
基本上,从 Windows7 到 Ubuntu 的过程中,该文件在某些地方被破坏了。
如何查看文件的二进制表示形式以了解发生了什么?
Basically, the file was broken some where along the way from Windows7 to Ubuntu.
How can I look at a binary representation of the file to see what happened?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
PHP 命令行脚本中仍然必须包含
开启符。
不会工作,它必须是
这是因为没有“php脚本”这样的东西。只有各种文本文件中嵌入了 PHP 代码块。即使在 CLI 模式下,PHP 也期望/要求至少看到一个
块。否则解释器将不会启动并且不会看到任何代码,即使您已经声明它是带有 shebang 的 PHP 脚本。
PHP cli 模式基本上是一种黑客入侵的事后想法。 PHP 最初是作为服务器端 CGI 脚本解析器,并且没有从根本上改变该模式。
PHP command line script still have to have the
<?php
opener in them.will not work, it has to be
This is because there's no such thing as a "php script". There are only various text files that have PHP code blocks embedded within them. Even in CLI mode, PHP expects/requires to see at least one
<?php
block. Otherwise the interpreter won't kick in and won't see any of the code, even though you've stated it's a PHP script with the shebang.PHP cli mode is basically a hacked-in afterthought. PHP started out as a server-side CGI script parser and has not fundamentally changed from that mode.
您是否使用
./
运行?IE:
Did you run with a
./
?IE:
尝试用 vi(m) 打开它,您就会看到问题。每行末尾的解释器 (^M) 都很糟糕。尝试转换它(从dos或dos2unix),这应该可以解决问题;-)
Try opening it with vi(m) and you'll see the problem. It's a bad intepreter (^M) at the end of each line. Try converting it (fromdos or dos2unix), this shoul'd fix the problem ;-)
我的猜测是,在 Windows 上创建的文件有一个令人困惑的 BOM。
My guess is that the files created on Windows have a BOM that is confusing matters.
在 Windows 计算机上使用 Notepad++ 时,可以通过转到
“编辑”>“EOL”将 EOL 字符从 Windows 更改为 UNIX。 EOL 转换 > UNIX 格式
仔细检查右下角的 Notepad++ 状态栏以确认您的选择。
保存并从命令行运行后,您应该发现 PHP 解释器指令现在已被正确识别。
When using Notepad++ on a Windows machine, one can change the EOL character from Windows to UNIX by going to
Edit > EOL Conversion > UNIX format
Double-check Notepad++'s status bar at the bottom-right to confirm your selection.
After saving and running from the command line, you should find that the PHP interpreter directive is now properly recognized.