如何清理不可见字符的源代码文件? [英] How can I clean source code files of invisible characters?

查看:30
本文介绍了如何清理不可见字符的源代码文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题:在我的 HTML/PHP 代码的某个地方有一个我似乎无法摆脱的隐藏的、不可见的字符.通过从 Firebug 复制并转换它,我将其标识为  或零宽度不间断空间".它在我的网站中显示为非空文本节点,并导致严重的布局问题.

I have a bizarre problem: Somewhere in my HTML/PHP code there's a hidden, invisible character that I can't seem to get rid of. By copying it from Firebug and converting it I identified it as  or 'Zero width no-break space'. It shows up as non-empty text node in my website and is causing a serious layout problem.

问题是,我无法摆脱它.即使打开 Invisibles(废话),我也无法在我的文件中看到它.我似乎无法找到它,似乎没有搜索工具可以找到它.我在可能的地方重写了我的代码,但它似乎在一个框架文件中更深的地方.

The problem is, I can't get rid of it. I can't see it in my files even when turning Invisibles on (duh). I can't seem to find it, no search tool seems to pick up on it. I rewrote my code around where it could be, but it seems to be somewhere deeper in one of the framework files.

如何通过文件或类似的字符代码查找字符?我对不同的工具持开放态度,但它们必须在 Mac OS X 上运行.

How can I find characters by charcode across files or something like that? I'm open to different tools, but they have to work on Mac OS X.

推荐答案

您在编辑器中找不到该字符,因为您在文本编辑器中找不到它.#FEFF 或 #FFFE 是所谓的字节顺序标记.它们是 Microsoft 的发明,用于在 Unicode 文件中说明多字节字符的存储顺序.

You don't get the character in the editor, because you can't find it in text editors. #FEFF or #FFFE are so-called byte-order marks. They are a Microsoft invention to tell in a Unicode file, in which order multi-byte characters are stored.

要摆脱它,请告诉您的编辑器将文件保存为 ANSI/ISO-8859 或 Unicode 无 BOM.如果您的编辑器不能这样做,您将不得不切换编辑器(可悲的是)或使用某种截断工具,例如十六进制编辑器,它允许您查看文件真正看起来.

To get rid of it, tell your editor to save the file either as ANSI/ISO-8859 or as Unicode without BOM. If your editor can't do so, you'll either have to switch editors (sadly) or use some kind of truncation tool like, e.g., a hex editor that allows you to see how the file really looks.

在谷歌搜索中,TextWrangler 似乎有一个UTF-8,没有 BOM".模式.否则,如果您对终端感到满意,则可以使用 Vim:

On googling, it seems, that TextWrangler has a "UTF-8, no BOM" mode. Otherwise, if you're comfortable with the terminal, you can use Vim:

:set nobomb

并保存文件.快点!

在文本文件中,字符总是最先.正如我提到的,支持 BOM 的编辑器根本不会向您展示.

The characters are always the very first in a text file. Editors with support for the BOM will not, as I mentioned, show it to you at all.

这篇关于如何清理不可见字符的源代码文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆