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:

ADVERTISEMENTS

  $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], '\r\n');
      $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:

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.