Tuesday, April 7th 2009

Uncurling PHP Curl’s character encoding problem
posted @ 3:06 am in [ Uncategorized ]

curl*, and specifically the PHP ‘glue’ that includes curl within the PHP function list, seems to have a strange party quirk where it automatically converts the results from the curl queries into UTF-8 encoding, which means you end up with extended character symbols such as £ signs being converted into weird looking versions like £, and back quotes converted into even weirder symbols such as ‘Caviar’

My first step was to use the PHP utf-8 decode function to get around this, utf8_decode(), however this copes with the £ symbols, but falls over with back quotes and similar ending up with ?Caviar?

So.. after a bit of reading around it turns out that the iconv function can convert between charactersets effortlessly, so the following to convert from UTF-8 and Windows-1252 works perfectly.

$text = iconv(“UTF-8″,”Windows-1252”,$text);

Job done 🙂

*(curl is a command line tool for transferring files with URL syntax – http://curl.haxx.se/)

One Response to “Uncurling PHP Curl’s character encoding problem”

  1. admin Says:

    Here’s a post from Daniel Stenberg, the curl project maintainer, saying that it’s nothing to do with curl..


Leave a Reply