PHPackages                             3f/pygmentize - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. 3f/pygmentize

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

3f/pygmentize
=============

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

1.3(8y ago)398884[1 issues](https://github.com/dedalozzo/pygmentize/issues)Apache-2.0PHPPHP &gt;=5.4.0

Since Feb 25Pushed 8y ago1 watchersCompare

[ Source](https://github.com/dedalozzo/pygmentize)[ Packagist](https://packagist.org/packages/3f/pygmentize)[ Docs](https://github.com/dedalozzo/pygmentize)[ RSS](/packages/3f-pygmentize/feed)WikiDiscussions master Synced today

READMEChangelog (4)DependenciesVersions (5)Used By (0)Security (1)

[![Latest Stable Version](https://camo.githubusercontent.com/204b6a7480f9587f0806d5669aa92fbe1094a24dba8c156d72a4826760e5d791/68747470733a2f2f706f7365722e707567782e6f72672f33662f7079676d656e74697a652f762f737461626c652e706e67)](https://packagist.org/packages/3f/pygmentize)[![Latest Unstable Version](https://camo.githubusercontent.com/30582202f60d8750929e2701ae6ffd1aa58f7c44be4370dcaeaf8209efd51400/68747470733a2f2f706f7365722e707567782e6f72672f33662f7079676d656e74697a652f762f756e737461626c652e706e67)](https://packagist.org/packages/3f/pygmentize)[![Build Status](https://camo.githubusercontent.com/39e986ecb94f5d08424eb4bb8a4bec2d32c64e170638e8b56ff44ff4802413cb/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f646564616c6f7a7a6f2f7079676d656e74697a652f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/dedalozzo/pygmentize/build-status/master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/d6b44f93de0af79dfa50d0bbc7d895adcc678dbae1ebbcd427d4a2be2eb0a81d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f646564616c6f7a7a6f2f7079676d656e74697a652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/dedalozzo/pygmentize/?branch=master)[![License](https://camo.githubusercontent.com/4bd67900f50414d928470ccb1d6756b1953839f0c8910c9b546ef96805cd635a/68747470733a2f2f706f7365722e707567782e6f72672f33662f7079676d656e74697a652f6c6963656e73652e737667)](https://packagist.org/packages/3f/pygmentize)[![Total Downloads](https://camo.githubusercontent.com/092f8bfc49b1b6ccc8b7feb06675bf3023a246c58ae1e411c84570dc0df6d5f9/68747470733a2f2f706f7365722e707567782e6f72672f33662f7079676d656e74697a652f646f776e6c6f6164732e706e67)](https://packagist.org/packages/3f/pygmentize)

Pygmentize
==========

[](#pygmentize)

Pygmentize is a wrapper to `pygmentize`, the command line interface provided by [Pygments](http://pygments.org), a Python syntax highlighter. Pygmentize is smart enough to raise an exception in case Pygments returns an error.

Composer Installation
---------------------

[](#composer-installation)

To install Pygmentize, you first need to install [Composer](http://getcomposer.org/), a Package Manager for PHP, following those few [steps](http://getcomposer.org/doc/00-intro.md#installation-nix):

```
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
-----------------------

[](#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"
    },
}
```

2. Run the following command in your project root dir:

```
composer update
```

Usage
-----

[](#usage)

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

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

Methods
-------

[](#methods)

### Pygmentize::highlight()

[](#pygmentizehighlight)

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

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

**Parameters**

- 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**

Returns the highlighted source code.

**Exceptions**

- RuntimeException

    Cannot execute the `pygmentize` command.
- RuntimeException

    Cannot create the temporary file with the source code.

Documentation
-------------

[](#documentation)

The documentation can be generated using [Doxygen](http://doxygen.org). A `Doxyfile` is provided for your convenience.

Requirements
------------

[](#requirements)

- PHP 5.4.0 or above.
- [Pygments](http://pygments.org) 1.6 or above.

Authors
-------

[](#authors)

Filippo F. Fadda -  -

License
-------

[](#license)

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

###  Health Score

33

—

LowBetter than 77% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 93.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~330 days

Total

4

Last Release

3050d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/311248?v=4)[Filippo Fadda](/maintainers/dedalozzo)[@dedalozzo](https://github.com/dedalozzo)

---

Top Contributors

[![dedalozzo](https://avatars.githubusercontent.com/u/311248?v=4)](https://github.com/dedalozzo "dedalozzo (30 commits)")[![cebe](https://avatars.githubusercontent.com/u/189796?v=4)](https://github.com/cebe "cebe (2 commits)")

---

Tags

phppygmentssyntax-highlighterwrapperSyntax highlighterpygmentspygmentize

### Embed Badge

![Health badge](/badges/3f-pygmentize/health.svg)

```
[![Health](https://phpackages.com/badges/3f-pygmentize/health.svg)](https://phpackages.com/packages/3f-pygmentize)
```

###  Alternatives

[vrana/jush

JUSH - JavaScript Syntax Highlighter

272.7M5](/packages/vrana-jush)[sheadawson/silverstripe-shortcodable

Provides a GUI for CMS users to insert Shortcodes into the HTMLEditorField + an API for developers to define Shortcodable DataObjects and Views

5018.1k5](/packages/sheadawson-silverstripe-shortcodable)[nahid/presento

Presento is a package for PHP data presenter

747.2k](/packages/nahid-presento)[ramsey/pygments

A PHP wrapper for Pygments, the Python syntax highlighter, forked from kzykhys/pygments.

103.0k2](/packages/ramsey-pygments)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
