PHP code example of demyanovs / php-highlight

1. Go to this page and download the library: Download demyanovs/php-highlight 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/ */

    

demyanovs / php-highlight example snippets




emyanovs\PHPHighlight\Highlighter;
use Demyanovs\PHPHighlight\Themes\ObsidianTheme;

$text = '
<pre><code class="language-php" data-file="php-highlight/examples/index.php">
&lt;?php
abstract class AbstractClass
{
    /**
     * Our abstract method only needs to define the 
        $prefix = "";
        if ($name === "Pacman") {
            $prefix = "Mr.";
        } elseif ($name === "Pacwoman") {
            $prefix = "Mrs.";
        } else {
            
        }
        
        return $prefix . " " . $name;
    }
}

$class = new ConcreteClass;
echo $class->prefixName("Pacman"), "\n";
echo $class->prefixName("Pacwoman"), "\n";
</code></pre>
';

$highlighter = (new Highlighter($text, ObsidianTheme::TITLE))
        ->showLineNumbers(true)
        ->showActionPanel(true);
echo $highlighter->parse();

$highlighter->showLineNumbers(true);
$highlighter->showActionPanel(true);

use Demyanovs\PHPHighlight\Highlighter;
use Demyanovs\PHPHighlight\Themes\Theme;
use Demyanovs\PHPHighlight\Themes\Dto\DefaultColorSchemaDto;
use Demyanovs\PHPHighlight\Themes\Dto\PHPColorSchemaDto;
use Demyanovs\PHPHighlight\Themes\Dto\XMLColorSchemaDto;

$defaultColorSchemaDto = new DefaultColorSchemaDto(
    '#000000', // background
    '#ffffff', // default text
    '#888888', // comment
    '#ff0000', // keyword
    '#00ff00', // string
    '#0000ff', // number
    '#ffff00'  // variable
);

$PHPColorSchemaDto = new PHPColorSchemaDto(
    '#0000BB', // keyword
    '#FF8000', // variable
    '#fbc201', // function
    '#007700', // string
    '#DD0000'  // comment
);

$XMLColorSchemaDto = new XMLColorSchemaDto(
    '#008000', // tag
    '#7D9029', // attribute
    '#BA2121', // string
    '#BC7A00'  // comment
);

$myTheme = new Theme(
    'myThemeTitle',
    $defaultColorSchemaDto,
    $PHPColorSchemaDto,
    $XMLColorSchemaDto
);

$highlighter = new Highlighter($text, 'myThemeTitle', [$myTheme]);
bash
$ composer 
html
<pre><code class="language-php" data-file="example.php" data-theme="darkula">
// or
<pre data-lang="php" data-file="example.php" data-theme="darkula"><code>