File: hello_world.php

package info (click to toggle)
php-text-figlet 1.0.2-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 140 kB
  • sloc: php: 290; xml: 108; makefile: 2
file content (35 lines) | stat: -rw-r--r-- 812 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php

/* UTF-8 convert to FIGlet Unicode */
/* iconv PHP module required */
function utf8tofiglet($str)
{
    // escape %u
    $str = str_replace('%u', sprintf('%%%%u%04X', ord('u')), $str);

    if (function_exists('iconv')) {
        $str = iconv('utf-8', 'ucs-2be', $str);
        $out = '';

        for ($i = 0, $len = strlen($str); $i<$len; $i++) {
            $code = ord($str[$i++]) * 256 + ord($str[$i]);

            $out .= $code < 128 ? $str[$i] : sprintf('%%u%04X', $code);
        }

        return $out;
    }

    return $str;
}

require_once 'Text/Figlet.php';

$figlet = new Text_Figlet();
$error  = $figlet->LoadFont('makisupa.flf');
if (PEAR::isError($error)) {
    echo 'Error: ' . $error->getMessage() . "\n";
} else {
    echo $figlet->LineEcho(utf8tofiglet('Hello, world!')) . "\n";
}
?>