1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-25 15:00:58 +01:00
phorge-phorge/externals/pear-figlet/docs/examples/hello_world.php
epriestley 935ced1edd Include "Figlet" and PEAR "Text_Figlet" in externals
Summary:
Ref T7785. This prepares for (but does not yet use) a pure PHP implementation of Figlet parsing and rendering.

Figlet is somewhat complex, but a parser already exists in PEAR. I'll make sure it's suitable and hook it up in the next diff.

Test Plan: N/A, code not reachable

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9408, T7785

Differential Revision: https://secure.phabricator.com/D14101
2015-09-13 12:30:48 -07:00

35 lines
No EOL
812 B
PHP

<?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";
}
?>