问题
How can I change all of my php/css/js files to utf character encoding? I can't get it to validate otherwise.
回答1:
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
回答2:
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.
来源:https://stackoverflow.com/questions/4675073/how-to-change-an-entire-websites-files-character-encoding-to-utf-8