开发者

How to change an entire website's files' character encoding to UTF-8?

How can I change all of my php/css/js files to utf character en开发者_StackOverflow社区coding? I can't get it to validate otherwise.


Have you tried the .htaccess option "AddCharset". It should work on the parent directory of where the .htaccess file is located plus all sub directories.

AddCharset UTF-8 .php

http://www.w3.org/International/questions/qa-htaccess-charset


You haven't said what encoding the files are in at the moment, or what operating system you are using. On my Ubuntu system, I have a command called iconv that will convert a single file. Using this, I would write a simple script to convert files "in-place". For example, to convert from iso8859-15 to utf-8, put this script in /tmp/convert:

#!/bin/sh
iconv -f iso8859-15 -t utf-8 "$1" > "$1.$$" && mv "$1.$$" "$1"

then run:

chmod 755 /tmp/convert

and then run find to execute that script on all .php, .js and .css files:

find /my/website/root -name \*.php -o -name \*.js -o -name \*.css -exec /tmp/convert {} \;

Remember to back up your files first in case the conversion doesn't do what you expect.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜