How to serve vCards with the right encoding

It seems that some programs which recognize vCards only support the ISO-8859-1 character set. So if you’re serving vCards on your web site, you might want to check if the encoding is correct. Try inserting a non-ASCII character like “å” in a note or address, and see if it comes out as a strange character when loading it from the web site.

To fix this, first make sure that your editor uses the correct encoding. Open the file, change the encoding, save the file, re-open it and correct the contents if the characters were messed up after saving (not all editors change characters correctly).

You might also have to override the server’s default encoding. If you’re using Apache 2, just add the following to the .htaccess file at the root of the web site:
AddCharset ISO-8859-1 .vcf
AddEncoding text/x-vcard .vcf

Turns out that didn’t work so well (I didn’t find out until i did a shift-reload). I had to turn to this one instead:
<Files *.vcf>
ForceType 'text/x-vcard; charset=ISO-8859-1'
</Files>

Advertisements

Convert XHTML to HTML with XSLT

After fiddling a bit with the “copy-no-ns” XSLT template, I’ve ended up with a style sheet which converts XHTML to HTML 4.01, so you can use it as a post-processing step when serving to Internet Explorer. Note that this has not been tested with alternative namespaces such as SVG or MathML.

Edit: After moving to PHP 5 and libxslt, it was necessary to trim the xmlns declarations down a bit. The new version is online now.

Edit 2: I got a bit of a surprise when reading the W3C recommendations for declaring encoding and MIME type. The new version is online, but you must provide the content type at run time (using XSLTProcessor::setParameter in PHP 5). Of course, you can just ignore that and specify your own if it’s static.