preg_replace_callback

Supported Versions: PHP 4 >= 4.0.5, PHP 5, PHP 7, PHP 8
Perform a regular expression search and replace using a callback
<?php preg_replace_callback(    string|array $pattern,    callable $callback,    string|array $subject,    int $limit = -1,    int &$count = null,    int $flags = 0): string|array|null
<?php     {

        $text = $this->text;



        $text = preg_replace_callback(

            $this->regexp(),

            fn (array $matches): string => str_replace(

                ['%{alt}', '%{src}'],

                [

                    $alt

                        ? $alt($matches[0])

                        : $matches[0],

                    Twemoji::emoji($matches[0])

                        ->base($this->base)

                        ->type($this->type)

                        ->url(),

                ],

                $replacement

            ),

            $text

        );



        return $text;

    }