protected function compressRepeatingCharacters(string $row): string
    {
        $callback = function ($matches) {
            $original = $matches[0];
            $repeat = strlen($original);
            $count = null;

            if ($repeat > 400) {
                $count .= str_repeat('z', floor($repeat / 400));
                $repeat %= 400;
            }

            if ($repeat > 19) {
                $count .= chr(ord('f') + floor($repeat / 20));
                $repeat %= 20;
            }

            if ($repeat > 0) {
                $count .= chr(ord('F') + $repeat);
            }

            return $count . substr($original, 1, 1);
        };

        return preg_replace_callback('/(.)(\1{2,})/', $callback, $row);
    }
protected function compressRepeatingCharacters(string $row): string
    {
        $callback = function ($matches) {
            $original = $matches[0];
            $repeat = strlen($original);
            $count = null;

            if ($repeat > 400) {
                $count .= str_repeat('z', floor($repeat / 400));
                $repeat %= 400;
            }

            if ($repeat > 19) {
                $count .= chr(ord('f') + floor($repeat / 20));
                $repeat %= 20;
            }

            if ($repeat > 0) {
                $count .= chr(ord('F') + $repeat);
            }

            return $count . substr($original, 1, 1);
        };

        return preg_replace_callback('/(.)(\1{2,})/', $callback, $row);
    }
protected function compressRepeatingCharacters ( string $ row ) : string { $ callback = function ( $ matches ) { $ original = $ matches [ 0 ] ; $ repeat = strlen ( $ original ) ; $ count = null ; if ( $ repeat > 400 ) { $ count .= str_repeat ( 'z' , floor ( $ repeat / 400 ) ) ; $ repeat %= 400 ; } if ( $ repeat > 19 ) { $ count .= chr ( ord ( 'f' ) + floor ( $ repeat / 20 ) ) ; $ repeat %= 20 ; } if ( $ repeat > 0 ) { $ count .= chr ( ord ( 'F' ) + $ repeat ) ; } return $ count . substr ( $ original , 1 , 1 ) ; } ; return preg_replace_callback ( '/(.)(\1{2,})/' , $ callback , $ row ) ; }
Compress characters which repeat.

@param string $row
@return string
Compress characters which repeat .