$limit ) { $text = mb_substr( $text, 0, $limit ); } return $text; } if ( strlen( $text ) > $limit ) { $text = substr( $text, 0, $limit ); } return $text; } /** * Keep an identifier made of letters, numbers, dots, underscores, and hyphens. * * @param mixed $value Raw value. * @param int $limit Maximum length. * @param string $fallback Value used when the result would be empty. * @return string */ public static function key( $value, $limit = 64, $fallback = '' ) { $value = strtolower( (string) $value ); $value = preg_replace( '/[^a-z0-9._-]/', '', $value ); $value = substr( (string) $value, 0, max( 1, (int) $limit ) ); if ( '' === $value ) { return $fallback; } return $value; } }