original_string: public static function encode_dbname($st, $maxlength = 50): string
    {
      $st = self::remove_accents(self::cast($st));
      $res = '';
  
      if ( !\is_int($maxlength) ){
        $maxlength = mb_strlen($st);
      }
  
      for ( $i = 0; $i < $maxlength; $i++ ){
        if ( mb_ereg_match('[A-z0-9]',mb_substr($st,$i,1)) ){
          $res .= mb_substr($st,$i,1);
        }
        else if ( (mb_strlen($res) > 0) &&
          (mb_substr($res,-1) != '_') &&
          ($i < ( mb_strlen($st) - 1 )) ){
          $res .= '_';
        }
      }
      if ( substr($res, -1) === '_' ){
        $res = substr($res, 0, -1);
      }
      return $res;
    }
code: public static function encode_dbname($st, $maxlength = 50): string
    {
      $st = self::remove_accents(self::cast($st));
      $res = '';
  
      if ( !\is_int($maxlength) ){
        $maxlength = mb_strlen($st);
      }
  
      for ( $i = 0; $i < $maxlength; $i++ ){
        if ( mb_ereg_match('[A-z0-9]',mb_substr($st,$i,1)) ){
          $res .= mb_substr($st,$i,1);
        }
        else if ( (mb_strlen($res) > 0) &&
          (mb_substr($res,-1) != '_') &&
          ($i < ( mb_strlen($st) - 1 )) ){
          $res .= '_';
        }
      }
      if ( substr($res, -1) === '_' ){
        $res = substr($res, 0, -1);
      }
      return $res;
    }
code_tokens: public static function encode_dbname ( $ st , $ maxlength = 50 ) : string { $ st = self :: remove_accents ( self :: cast ( $ st ) ) ; $ res = '' ; if ( ! \ is_int ( $ maxlength ) ) { $ maxlength = mb_strlen ( $ st ) ; } for ( $ i = 0 ; $ i < $ maxlength ; $ i ++ ) { if ( mb_ereg_match ( '[A-z0-9]' , mb_substr ( $ st , $ i , 1 ) ) ) { $ res .= mb_substr ( $ st , $ i , 1 ) ; } else if ( ( mb_strlen ( $ res ) > 0 ) && ( mb_substr ( $ res , - 1 ) != '_' ) && ( $ i < ( mb_strlen ( $ st ) - 1 ) ) ) { $ res .= '_' ; } } if ( substr ( $ res , - 1 ) === '_' ) { $ res = substr ( $ res , 0 , - 1 ) ; } return $ res ; }
docstring: Returns a corrected string for database naming.
  
  ```php
  \bbn\x::dump(\bbn\str::encode_dbname('my.database_name ? test  :,; !plus'));
  // (string) "my_database_name_test_plus"
  ```
  
  @param string $st The name as string.
  @param int $maxlength The maximum length, default: "50".
  @return string
docstring_tokens: Returns a corrected string for database naming .