PHP: GeSHi Syntax Highlighter Enable / Disable Line Numbers

To enable or disable line numbers in GeSHi Syntax Highlighter, you can use the line_numbers property in the GeSHi object. Here’s an example of how to enable line numbers in PHP:

<?php
include 'geshi.php';

$source = <<<'CODE'
// Your code here
CODE;

$geshi = new GeSHi($source, 'php');
$geshi->set_header_type(GESHI_HEADER_PRE_VALID);
$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);

echo $geshi->parse_code();
?>

And here’s an example of how to disable line numbers:

<?php
include 'geshi.php';

$source = <<<'CODE'
// Your code here
CODE;

$geshi = new GeSHi($source, 'php');
$geshi->set_header_type(GESHI_HEADER_PRE_VALID);
$geshi->enable_line_numbers(GESHI_NO_LINE_NUMBERS);

echo $geshi->parse_code();
?>

Note that the enable_line_numbers method takes either GESHI_NORMAL_LINE_NUMBERS or GESHI_NO_LINE_NUMBERS as its argument.

Leave a Comment