Pygmentize is a wrapper to `pygmentize`, the command line interface provided by Pygments, a python syntax highlighter.

1.3 2017-11-13 17:53 UTC

This package is not auto-updated.

Last update: 2020-05-29 17:08:15 UTC


Latest Stable Version Latest Unstable Version Build Status Scrutinizer Code Quality License Total Downloads


Pygmentize is a wrapper to pygmentize, the command line interface provided by Pygments, a Python syntax highlighter. Pygmentize is smart enough to raise an exception in case Pygments returns an error.

Composer Installation

To install Pygmentize, you first need to install Composer, a Package Manager for PHP, following those few steps:

curl -s https://getcomposer.org/installer | php

You can run this command to easily access composer from anywhere on your system:

sudo mv composer.phar /usr/local/bin/composer

Pygmentize Installation

Once you have installed Composer, it's easy install Pygmentize.

  1. Edit your composer.json file, adding Pygmentize to the require section:
    "require": {
        "3f/pygmentize": "dev-master"
  1. Run the following command in your project root dir:
composer update


Pygmentize is really easy to use, having only one static method. You just call highlight() like follows:

Pygmentize::highlight($code, $language);



public static function highlight(
    $encoding = "utf-8",
    $formatter = "html",
    $style = "borland"

Formats the provided source code using the specified formatter and style.


  • source

    The source code.

  • language

    The programming language name of the source code.

  • encoding

    The file input and output encodings.

  • formatter

    The output will be created using the provided formatter.

  • style

    The style used by the formatter.


Returns the highlighted source code.


  • RuntimeException

    Cannot execute the pygmentize command.

  • RuntimeException

    Cannot create the temporary file with the source code.


The documentation can be generated using Doxygen. A Doxyfile is provided for your convenience.


  • PHP 5.4.0 or above.
  • Pygments 1.6 or above.


Filippo F. Fadda - filippo.fadda@programmazione.it - http://www.linkedin.com/in/filippofadda


Pygmentize is licensed under the Apache License, Version 2.0 - see the LICENSE file for details.