Konstrukt decodeCharset and utf8_decode

Hi.
I’m peeping into http://konstrukt.dk/ framework ,by the way very smart work imho ;), but I don’t
understand the use of utf8_decode in this method (k_http_Request class)


protected function decodeCharset($input) {
    if (is_array($input)) {
      $output = Array();
      foreach ($input as $key => $value) {
        $output[$key] = $this->decodeCharset($value);
      }
      return $output;
    }
    return utf8_decode($input);
  }

I find it quite strange I mean
usually you’ve got a html page with
charset=utf-8 and the DB with the collation
set utf8_general_ci.

Could anyone explain me this choice ?

Bye.

I might.

You can follow one of two strategies, if you want to support UTF-8 in PHP. Either you use UTF-8 all the way through; The sourcecode is encoded as UTF-8, the database is UTF-8 and any externally supplied data, is read as UTF-8. This works fine except that PHP’s libraries all expect strings to be singlebyte (iso-8859-1). Thus the string manipulation functions will give wrong results.

The other strategy you can take, is to use UTF-8 in the presentation layer, but use latin1 on the inside. To do this, you have to encode output to UTF-8 and conversely decode from UTF-8 -> latin1 for input. Konstrukt takes this approach.

Arguably, it’s a suboptimal solution, since it basically limits you to latin1. However, as long as the standard for PHP is latin1, that’s also what Konstrukt is supporting. Once PHP6 comes out, the transition should be a matter of removing the encode/decode functions and converting files to UTF-8.

If you need full unicode support now, you can use the first strategy I mentioned. To do so, you would simply remove the encode/decode functions. I haven’t had the need for it yet, so I haven’t made a hook to do it, but if you need it, please file a feature-request.

Otherwise, you can simply hack the code – Comment out decodeCharset(), and change k_http_Response->outputEncoder to null.

Thanks just a lot for the full reply.
Bye.

I love this forum :smiley:

Another satisfied member

Thread Closed