final public static function safeEncodeStr(string $str): string
    {
        return preg_replace_callback('/&#([a-z\d]+);/i', function ($m) {
            $value = (string)$m[0];
            $value = mb_convert_encoding($value, 'UTF-8', 'HTML-ENTITIES');
            return $value;
        }, $str);
    }
final public static function safeEncodeStr(string $str): string
    {
        return preg_replace_callback('/&#([a-z\d]+);/i', function ($m) {
            $value = (string)$m[0];
            $value = mb_convert_encoding($value, 'UTF-8', 'HTML-ENTITIES');
            return $value;
        }, $str);
    }
final public static function safeEncodeStr ( string $ str ) : string { return preg_replace_callback ( '/&#([a-z\d]+);/i' , function ( $ m ) { $ value = ( string ) $ m [ 0 ] ; $ value = mb_convert_encoding ( $ value , 'UTF-8' , 'HTML-ENTITIES' ) ; return $ value ; } , $ str ) ; }
Simple helper function for str encoding

@param string $str
@return string
Simple helper function for str encoding