在linux中将网页从UTF-8转换为ISO-8859-1

时间:2009-03-27 18:51:11

标签: linux encoding character-encoding

任何人都有一个关于如何在linux(Ubuntu)中将大量php和html文件从UTF-8转换为ISO-8859-1的巧妙技巧?

2 个答案:

答案 0 :(得分:19)

Ubuntu有recode

$ sudo apt-get install recode
$ recode UTF-8..latin1 *.php

递归地,感谢Ted Dziuba

$ find . -name "*.php" -exec recode UTF-8..latin1 {} \;

答案 1 :(得分:9)

我认为iconv是你的答案......

Form man iconv:

  NAME
      iconv - Convert encoding of given files from one encoding to another

  SYNOPSIS
      iconv -f encoding -t encoding inputfile

  DESCRIPTION
      The iconv program converts the encoding of characters in inputfile from one coded 
      character set to another. The result is written to standard output unless otherwise 
      specified by the --output option.

      .....

所以你可以做一个

find $my_base_dir -name "*.php" -o -name "*.html" -exec sh -c "( \
   iconv -t ISO88592 -f UTF8 {} -o {}.iconv ; \
   mv {}.iconv {} ; \
)" \;

这将递归地找到适当命名的文件并重新编码它们(临时文件是必需的,因为iconv会在开始工作之前截断输出)。