PHP: GeSHi Syntax Highlighter Enable / Disable Line Numbers

I‘m using GeSHi under php to highlight a source code. How do I turn on or off line numbers using GeSHi?

GeSHi has the ability to add line numbers to your code. You can turn on or off this features as per your requirements. To highlight a source with line numbers, you call the enable_line_numbers() method. The syntax is:

  $geshi->enable_line_numbers($flag);

Where $flag is one of the following:

  • GESHI_NORMAL_LINE_NUMBERS – Use normal line numbering.
  • GESHI_FANCY_LINE_NUMBERS – Use fancy line numbering.
  • GESHI_NO_LINE_NUMBERS – Disable line numbers (default).

The following code will disable line numbers:

      $tabstop = 2;
      $code = trim($matches[5], 'rn');
      $code = str_replace('< pre>', '</pre>', $code);
 
      // Create a new GeSHi for our code
      $geshi =& new GeSHi($code, $lang);
      $geshi->set_tab_width($tabstop);
 
      //Disable line numbers
      $geshi->enable_line_numbers(GESHI_NO_LINE_NUMBERS);
      return $geshi->parse_code();

To enable fancy line numbering:

      //Enable fancy numbering:
      $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);

Reference:

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Total
0
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post

How to Make Website WCAG Compliant?

Next Post

Link download Kali Linux 2020.1 (ISO + Torrent)

Related Posts