PHP Classes

PHP Prettify: Output colored PHP code highlighted using themes

Recommend this page to a friend!
  Info   View files Documentation   View files View files (9)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 155 This week: 1All time: 9,021 This week: 560Up
Version License PHP version Categories
php_prettify 1.0.0BSD License5HTML, PHP 5, Parsers
Description 

Author

This package can output colored PHP code highlighted using themes.

It can take the name a file of PHP script and parses it to extract its structure.

The class returns a HTML string with the original PHP code formatted to highlight different aspects of the PHP syntax. The resulting output can:

- Include line numbers on the side of the code
- Have a specific line being highlighted in a different way
- Return only a part of the original code being highlighted, like for instance only a class definition
- Use a separate configuration file in JSON format to define output presentation themes for different versions of PHP like PHP 5 and PHP 7

Innovation Award
PHP Programming Innovation award nominee
August 2020
Number 3
PHP comes with built-in support to parse PHP code to generate HTML that can display the code in a highlighted format using color.

This package implements a better solution for displaying PHP code in Web pages.

It can highlight the code using colors, add line numbering, highlight specific lines or just part of the code of a script, and highlighting the code using themes configured using separate files in JSON format.

Manuel Lemos
Picture of chrys ugwu
  Performance   Level  
Name: chrys ugwu <contact>
Classes: 16 packages by
Country: Nigeria Nigeria
Age: 30
All time rank: 16897 in Nigeria Nigeria
Week rank: 416 Up8 in Nigeria Nigeria Down
Innovation award
Innovation award
Nominee: 4x

Documentation

 

Details

PHP Prettify

Outputs or returns html markup for a syntax highlighted version of the given PHP code using your defined colors. includes PHP 7.1 version

<?php

use PhpPrettify\Highlight;

/*
* @param (string) file name or string of PHP code to be highlighted
* @param (bool) set to true if @param1 is a file
* @param (bool) allow caching of processed text (currently work for files only)
*/
echo '<pre>', Highlight::render('code.txt', true, true), '</pre>';

alt tag alt tag

showLineNumber

/
* @param (bool) displays line number if true.
* @param (int) line at wich code rendering begins.
* @return (void)
*/
Highlight::showLineNumber($flag, $start_line);

theme

/
* @param (string) name of theme base on json file.
* @param (string) default theme to use if @param1 was not found.
* @return (int) (2 used @param1, 1 used @param2, 0 none, -1 no theme.json file found)
*/
Highlight::showLineNumber($flag, $start_line);

setHighlight

/
* @param (int) line to highlight
* @param (array) attributes to add to line eg (array('class' => 'clsName'))
* @param (bool) allows only one(last called) highlight.
*/
Highlight::setHighlight($line, array $attributes, $override);


  Files folder image Files  
File Role Description
Files folder imageimages (2 files)
Files folder imagesrc (2 directories)
HTML file demo.html Doc. Documentation
Plain text file LICENSE Lic. License text
Plain text file README.md Doc. Documentation

  Files folder image Files  /  images  
File Role Description
  Image file dark.png Data Auxiliary data
  Image file light.png Data Auxiliary data

  Files folder image Files  /  src  
File Role Description
Files folder imagePHP5.3 (2 files)
Files folder imagePHP7.0 (2 files)

  Files folder image Files  /  src  /  PHP5.3  
File Role Description
  Plain text file Highlight.php Class Class source
  Plain text file theme.json Data Auxiliary data

  Files folder image Files  /  src  /  PHP7.0  
File Role Description
  Plain text file Highlight.php Class Class source
  Plain text file theme.json Data Auxiliary data

 Version Control Unique User Downloads Download Rankings  
 100%
Total:155
This week:1
All time:9,021
This week:560Up