PHP code example of php-school / psx

1. Go to this page and download the library: Download php-school/psx library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

php-school / psx example snippets


use PhpSchool\PSX\Factory;

$highlighterFactory = new Factory;
$highlighter = $highlighterFactory->__invoke();

echo $highlighter->highlight($phpCode);

use PhpParser\ParserFactory;
use Colors\Color;
use PhpSchool\PSX\SyntaxHighlighter;
use PhpSchool\PSX\SyntaxHighlightPrinter;
use PhpSchool\PSX\SyntaxHighlighterConfig;
use PhpSchool\PSX\ColorsAdapter;

$parserFactory  = new ParserFactory;
$color          = new Color;
$color->setForceStyle(true);
$highlighter = new SyntaxHighlighter(
    $parserFactory->create(ParserFactory::PREFER_PHP7),
    new SyntaxHighlightPrinter(
        new SyntaxHighlighterConfig([
            SyntaxHighlighterConfig::TYPE_KEYWORD       => Colours::GREEN,
            SyntaxHighlighterConfig::TYPE_RETURN_NEW    => Colours::BLACK,
        ]),
        new ColorsAdapter($color)
    )
);