Home Page
RABiD BUNNY FEVER
K.T.K

  • September 18, 2019, 07:29:17 PM *
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search  

News:

Official site launch very soon, hurrah!


Author Topic: UTF8 fix for iOS mail  (Read 3129 times)

Dakusan

  • Programmer Person
  • Administrator
  • Hero Member
  • *****
  • Posts: 524
    • View Profile
    • Dakusan's Domain
UTF8 fix for iOS mail
« on: July 25, 2013, 09:29:35 AM »

Original post for UTF8 fix for iOS mail can be found at https://www.castledragmire.com/Posts/UTF8_fix_for_iOS_mail.
Originally posted on: 07/25/13

Nowadays, it just makes sense to do everything in utf8 from the start. Most everything of consequence now supports it, it keeps byte count down for most anyone using an alphabet that is primarily latin, it is compatible with a old of older software, and can help lead to some useful shortcuts in programming. A very good number of libraries and languages even assume it as the default character encoding now.

It’s especially nice for html and web pages, so content can just be pasted in as-is, except of course for single and double quotes (which I always replace with ’ “ ” anyways) and < > &. However, I was recently thrown for a loop when my utf8 encoding was not being read correctly in Apple’s iOS mail client. After lots of testing and research, I came to the conclusion that it just plain doesn’t support utf-8 by default! I think I read somewhere you have to install foreign language packs to make it available, but that doesn’t help our normal latin-based-alphabet users.


The simple solution for diacritic (and other html encodable) characters is to just encode them as html: (only supported for php>=5.3.4)

function EncodeForIOS($String) //This assumes the following characters are already encoded (line 2): & < >
{
   $MailHTMLConvertArray=get_html_translation_table(HTML_ENTITIES, ENT_NOQUOTES, 'UTF-8');
   unset($MailHTMLConvertArray['&'], $MailHTMLConvertArray['<'], $MailHTMLConvertArray['>']);
   return strtr($String, $MailHTMLConvertArray);
}
Logged