Supported Versions: PHP 4, PHP 5, PHP 7, PHP 8
Perform a regular expression search and replace
<?php preg_replace(    string|array $pattern,    string|array $replacement,    string|array $subject,    int $limit = -1,    int &$count = null): string|array|null
<?php     private function stripAnsi(string $text): string

    {

        $text = preg_replace('/\x1b([\[()])[;?0-9]*[0-9A-Za-z]/', "", $text);

        $text = preg_replace('/\x1b([\[()])[;?0-9]*[0-9A-Za-z]/', "", $text);

        $text = preg_replace('/[\x03|\x1a]/', "", $text);

        return $text;
<?php     private function stripAnsi(string $text): string

    {

        $text = preg_replace('/\x1b([\[()])[;?0-9]*[0-9A-Za-z]/', "", $text);

        $text = preg_replace('/\x1b([\[()])[;?0-9]*[0-9A-Za-z]/', "", $text);

        $text = preg_replace('/[\x03|\x1a]/', "", $text);

        return $text;

    }
<?php     {

        $text = preg_replace('/\x1b([\[()])[;?0-9]*[0-9A-Za-z]/', "", $text);

        $text = preg_replace('/\x1b([\[()])[;?0-9]*[0-9A-Za-z]/', "", $text);

        $text = preg_replace('/[\x03|\x1a]/', "", $text);

        return $text;

    }