From the console the file command can be used to describe a file (with the encoding it is saved as)
user@comp:~/workspace/project$ file dbase/init.sql dbase/init.sql: UTF-8 Unicode (with BOM) English text |
From the console the file command can be used to describe a file (with the encoding it is saved as)
user@comp:~/workspace/project$ file dbase/init.sql dbase/init.sql: UTF-8 Unicode (with BOM) English text |
PHPMailer does not seem to auto-detect encodings, so if you wish to send mail in (for instance UTF-8) you need to tell PHPMailer this. Thankully that is very easy
$phpMailerObject->CharSet = 'UTF-8'; |
To send a mail from PHP encoded as UTF-8 is fairly easy to do by modifying the headers.
//Sender with special chars (UTF-8) encoded mail('mail@example.com', '=?UTF-8?B?'.base64_encode($subjectString).'?=', $messageString, "MIME-Version: 1.0\r\nContent-type: text/plain; charset=UTF-8\r\n"); //Sender not UTF-8 encoded mail('mail@example.com', 'sender@mail.com', $messageString, "MIME-Version: 1.0\r\nContent-type: text/plain; charset=UTF-8\r\n"); |
To get a html page to display UTF-8 encoded text correctly (without setting a default charset) simply add the following to the head of the html page.
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
These characters are the Byte Order Mark (BOM) of the Unicode Standard.
This can be solved in two ways:
:set nobomb |
and then save the file
If your store uses DIBS to manage payments, then the risk is that you have to worry about characters like åäö.
What we had to do is to make the form post the data as ISO-8859-1.
We did this by adding accept-charset=”iso-8859-1″ to the forms that we send to DIBS.
In “/app/design/frontend/default/blank/template/dibs/standard/redirect_paymentwindow.phtml”
56 | <form action="https://payment.architrade.com/paymentweb/start.action" method="post" name="dibs" id="dibs" accept-charset="iso-8859-1"> |
Once we had done this then the order details were shown correctly on the DIBS page (yes, the Chinese chars are just a test, I have no idea what it might say)
If you have a file that is saves as ISO-8859-1 (or ISO-LATIN-1 if you like to call it that) and wish to convert it to UTF-8 you can use:
iconv --from-code=ISO-8859-1 --to-code=UTF-8 ./oldfile.htm > ./newfile.html |
This will create a new file with the converted encoding.
iconv can of of course convert to and from several other charsets. To see a list of all the encodings that iconv can work with use:
iconv -l |
If you wish to massconvert files find can be used with exec
find . -name "*.txt" -exec iconv -f ISO-8859-1 -t UTF-8 {} -o {}.utf8 \; |
If you do not wish to change character encoding for the entire server, but only one site (or only one directory) then this is possible to do using .htaccess.
AddDefaultCharset UTF-8 |
If you only wish to do this to php or htm files (and not all files)
<FilesMatch "\.(htm|php)$"> AddDefaultCharset UTF-8 </FilesMatch> |
If you wish to modify the mime-type as well as the encoding (on html files in this example)
AddType 'text/html; charset=UTF-8' html |