Ignore:
Timestamp:
Oct 28, 2008, 8:43:39 PM (12 years ago)
Author:
nico
Message:
  • Add unicode support in sample program figfont.php
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/caca-php/examples/figfont.php

    r3132 r3133  
    22<?php
    33
     4function unistr_to_ords($str, $encoding = 'UTF-8'){       
     5        $str = mb_convert_encoding($str, "UCS-4BE", $encoding);
     6        $result = array();
     7
     8        for ($i = 0; $i < mb_strlen($str, "UCS-4BE"); $i++){       
     9                $c = mb_substr($str, $i, 1, "UCS-4BE");                   
     10                $val = unpack("N", $c);           
     11                $result[] = $val[1];               
     12        }       
     13        return $result;
     14}
     15
     16
    417if ($argc < 3) {
    5         die("Too few arguments.\nUsage: cmd <path of font> <string>\n");
     18        die("Too few arguments.\nUsage: cmd <path of font> <utf8 string>\n");
    619}
    720
     
    1225}
    1326
    14 $str = $argv[2];
     27$chars = unistr_to_ords($argv[2]);
    1528$color = 0;
    16 for ($i = 0; $i < strlen($str); $i++) {
     29foreach ($chars as $c) {
    1730        caca_set_color_ansi($cv, 1 + (($color += 4) % 15), CACA_TRANSPARENT);
    18         caca_put_figchar($cv, ord($str[$i]));
     31        caca_put_figchar($cv, $c);
    1932}
    2033
     
    2235
    2336
    24 
Note: See TracChangeset for help on using the changeset viewer.