Using the Text_Figlet class

Text_Figlet has only two methods you can use: loadFont() to select a FIGlet font file that will be used later on, and lineEcho() that actually returns the passed text, rendered with the previously selected font.

loadFont() takes the name/path of the FIGlet font file (*.flf or *.flf.gz) as first parameter, and the option if German characters should also be loaded as second, optional parameter (defaults to true). The method either returns true if the font could be loaded, or a PEAR_Error in case of a problem.

lineEcho() can be called (multiple times if needed) after loading the font with loadFont(). The method takes the text that should be rendered using the font as first parameter, and an optional second parameter that determines if the text should be outputted in HTML text. In this case, special characters are escaped and everything is setup so that the text will look correctly. This parameter defaults to false. You should also wrap the line into <pre> tags, since they will monospace the text. Unlike the name implies, the rendered text is not echoed but returned.

Rendering "Hello, world!" using PHP

<?php
require_once 'Text/Figlet.php';

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

The Text_Figlet package already ships some fonts. They are stored in its data directory which can be found calling pear config-get data_dir, and appending Text_Figlet/fonts/ to it. It will contain the following fonts:

  • 3-d.flf

  • alligator2.flf

  • bell.flf

  • block.flf

  • contessa.flf

  • cybermedium.flf

  • isometric1.flf

  • larry3d.flf

  • script.flf

  • slant.flf

Passing one of the font names to loadFont() will automatically look them up in the Text_Figlet font data directory if they are not found.

Text_Highlighter (Next)
Last updated: Sat, 16 Feb 2019 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

There are no user contributed notes for this page.