PHP Prettify: Output colored PHP code highlighted using themes

Recommend this page to a friend!

  Author Author  
Picture of chrys ugwu
Name: chrys ugwu <contact>
Classes: 10 packages by
Country: Nigeria Nigeria
Innovation award
Innovation award
Nominee: 4x


  Detailed description   Download Download .zip .tar.gz  
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

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);


  Classes of chrys ugwu  >  PHP Prettify  >  Download Download .zip .tar.gz  >  Support forum Support forum  >  Blog Blog  >  RSS 1.0 feed RSS 2.0 feed Latest changes  
Name: PHP Prettify
Base name: php_prettify
Description: Output colored PHP code highlighted using themes
Version: -
PHP version: 5
License: BSD License
 
  Groups   Applications   Files Files  

  Groups  
Group folder image HTML HTML generation and processing View top rated classes
Group folder image PHP 5 Classes using PHP 5 specific features View top rated classes
Group folder image Parsers Programming language interpreters and format parsers View top rated classes


  Innovation Award  
PHP Programming Innovation award nominee
August 2020
Nominee
Vote
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

  Applications that use this package  
No pages of applications that use this class were specified.

Add link image If you know an application of this package, send a message to the author to add a link here.

  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

Download Download all files: php_prettify.tar.gz php_prettify.zip
NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.

For more information send a message to info at phpclasses dot org.