Library, which allows you to highlight your PHP code in terminal
Installation via composer:
composer require mkgor/highlighter
<?php
require_once "vendor/autoload.php";
$highlighter = new \Highlighter\Highlighter();
echo $highlighter->getWholeFile(__FILE__);
<?php
require_once "vendor/autoload.php";
$highlighter = new \Highlighter\Highlighter();
echo $highlighter->getSnippet(__FILE__, 3);
<?php
require_once "vendor/autoload.php";
$highlighter = new \Highlighter\Highlighter();
echo $highlighter->getSpecifiedSnippet(__FILE__, 3, 5);
<?php
require_once "vendor/autoload.php";
$highlighter = new \Highlighter\Highlighter();
echo $highlighter->getLine(__FILE__, 3);
You can use same functions with suffix WithoutNumbers
to highlight code without line numbers:
<?php
require_once "vendor/autoload.php";
$highlighter = new \Highlighter\Highlighter();
echo $highlighter->getWholeFileWithoutNumbers(__FILE__);
This highlighter supports custom themes. It has built-in themes, but you can create your own by implementing Highlighter\Theme\ThemeInterface
So, to set theme, just call setTheme
method of Highlighter
<?php
require_once "vendor/autoload.php";
$highlighter = new \Highlighter\Highlighter();
$highlighter->setTheme(new Highlighter\Theme\DefaultThemes\Minimalistic());
echo $highlighter->getWholeFile(__FILE__);