PHP code example of giberti / commonmark-emoji-extension

1. Go to this page and download the library: Download giberti/commonmark-emoji-extension 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/ */

    

giberti / commonmark-emoji-extension example snippets


use Giberti\EmojiExtension\EmojiExtension;

// Get a configured instance of the converter
$environment = new \League\CommonMark\Environment\Environment();
$environment->addExtension(new \League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension());
$environment->addExtension(new \Giberti\EmojiExtension\EmojiExtension());
$converter = new \League\CommonMark\MarkdownConverter($environment);

// <p>I can haz <span class="emoji" title="hot_beverage">☕</span>?</p>
echo $converter->convert('I can haz :hot_beverage:?')->getContent();

$aliases = [
    ':coffee:' => ':hot_beverage:',
    ':smile:' => ':grinning_face_with_smiling_eyes:',
    // ... any other aliases you wish to support
];

// Get a configured instance of the converter
$environment = new \League\CommonMark\Environment\Environment();
$environment->addExtension(new \League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension());
$environment->addExtension(new \Giberti\EmojiExtension\EmojiExtension($aliases));
$converter = new \League\CommonMark\MarkdownConverter($environment);

// <p>I can haz <span class="emoji" title="coffee">☕</span>?</p>
echo $converter->convert('I can haz :coffee:?')->getContent();