我有一个包含300多个HTML文件的目录,我需要解析数据并将其放入一个新的HTML模板,该模板与预先呈现的HTML实体(例如,出现在某些文件中的平方根√
。我在Ruby 1.9的阅读吨的职位在大约编码最后几个小时,想的东西:File.Open encoding呈现HTML实体
File.read("_pending/testdir/filename.html", :encoding=>"UTF-8")
和
trans = Iconv.new('UTF-8', 'IBM437')
input_text = File.read("_pending/testdir/filename.html")
output_text = trans.iconv(input_text)
puts output_text
所有没有运气。一旦转换成平方根符号,在浏览器中以及原始HTML标记中仍然显示为√
,但Iconv
解决方案的输出AªAo
在控制台puts
时仍然如此。
设置
的Windows Server 2008 R2
红宝石1.9.3p194(2012-04-20)[I386-的mingw32]
编码名称返回IBM437
当我做HTML_FILE.external_encoding.name
。
你确定他们是'IBM437'吗? [Win-1252](http://en.wikipedia.org/wiki/Windows-1252)或[ISO-8859-1](http://en.wikipedia.org/wiki/ISO-8859-1)是更可能的候选人。另一种方法是做一个预先通过并将复选标记插入实体。 –
我同意,但似乎很奇怪,但是当我运行下面的代码时,我得到了'IBM437'。 'test = File.open(“filename.html”) puts test.external_encoding.name test.close' – NotJustClarkKent
感谢Tin Man,事实证明,我只是一个白痴,Ruby不是一个问题,所有......感谢您代我进行此项调查。 – NotJustClarkKent