This commit is contained in:
2021-11-24 23:46:26 +08:00
parent a7db58d7e4
commit 40b4c2a4c9
+19 -13
View File
@@ -30,8 +30,11 @@ class Str
if ($length < 1) $length = 20; if ($length < 1) $length = 20;
$default = self::STRING . strtoupper(self::STRING) . self::NUMBER; $default = self::STRING . strtoupper(self::STRING) . self::NUMBER;
$default = str_split($default); $default = str_split($default);
$string .= str_repeat($default[array_rand($default)], $length); for ($i = 0; $i < $length; $i++) {
return (string)$string; shuffle($default);
$string .= $default[array_rand($default)];
}
return $string;
} }
/** /**
@@ -45,7 +48,10 @@ class Str
$number = ''; $number = '';
$default = str_split(self::NUMBER); $default = str_split(self::NUMBER);
if ($length < 1) $length = 1; if ($length < 1) $length = 1;
$number .= str_repeat($default[array_rand($default)], $length); for ($i = 0; $i < $length; $i++) {
shuffle($default);
$number .= $default[array_rand($default)];
}
return $number; return $number;
} }
@@ -57,7 +63,7 @@ class Str
* *
* @return string * @return string
*/ */
public static function cut_str_utf8($string, $sullen, bool $strip_tags = true, string $append = '...'): string public static function cut_str_utf8($string, $sullen, bool $strip_tags = TRUE, string $append = '...'): string
{ {
if ($strip_tags) { if ($strip_tags) {
$string = strip_tags($string); $string = strip_tags($string);
@@ -83,10 +89,10 @@ class Str
* @return bool * @return bool
* 判断是否为json字符串 * 判断是否为json字符串
*/ */
public static function isJson($data, $callback = null): bool public static function isJson($data, $callback = NULL): bool
{ {
$json = !is_null(json_decode($data)) && !is_numeric($data); $json = !is_null(json_decode($data)) && !is_numeric($data);
if ($json && is_callable($callback, true)) { if ($json && is_callable($callback, TRUE)) {
return call_user_func($callback, $data); return call_user_func($callback, $data);
} }
return $json; return $json;
@@ -99,10 +105,10 @@ class Str
* @return bool * @return bool
* 判断是否序列化字符串 * 判断是否序列化字符串
*/ */
public static function isSerialize($data, $callBack = null): bool public static function isSerialize($data, $callBack = NULL): bool
{ {
$false = !empty($data) && swoole_unserialize($data) !== false; $false = !empty($data) && swoole_unserialize($data) !== FALSE;
if ($false && is_callable($callBack, true)) { if ($false && is_callable($callBack, TRUE)) {
return call_user_func($callBack, $data); return call_user_func($callBack, $data);
} }
return $false; return $false;
@@ -184,7 +190,7 @@ class Str
* @return array * @return array
* 剩余天,带分秒 * 剩余天,带分秒
*/ */
public static function timeout($endTime, int $startTime = null): array public static function timeout($endTime, int $startTime = NULL): array
{ {
$endTime = $endTime - (!empty($startTime) ? $startTime : time()); $endTime = $endTime - (!empty($startTime) ? $startTime : time());
@@ -227,7 +233,7 @@ class Str
public static function clear(string $string): array|string|null public static function clear(string $string): array|string|null
{ {
$char = '。、!?:;﹑•"…‘’“”〝〞∕¦‖— 〈〉﹞﹝「」‹›〖〗】【»«』『〕〔》《﹐¸﹕︰﹔!¡?¿﹖﹌﹏﹋'´ˊˋ―﹫︳︴¯_ ̄﹢﹦﹤‐­˜﹟﹩﹠﹪﹡﹨﹍﹉﹎﹊ˇ︵︶︷︸︹︿﹀︺︽︾ˉ﹁﹂﹃﹄︻︼()'; $char = '。、!?:;﹑•"…‘’“”〝〞∕¦‖— 〈〉﹞﹝「」‹›〖〗】【»«』『〕〔》《﹐¸﹕︰﹔!¡?¿﹖﹌﹏﹋'´ˊˋ―﹫︳︴¯_ ̄﹢﹦﹤‐­˜﹟﹩﹠﹪﹡﹨﹍﹉﹎﹊ˇ︵︶︷︸︹︿﹀︺︽︾ˉ﹁﹂﹃﹄︻︼()';
return preg_replace(array("/[[:punct:]]/i", '/[' . $char . ']/u', '/[ ]{2,}/'), '', $string); return preg_replace(["/[[:punct:]]/i", '/[' . $char . ']/u', '/[ ]{2,}/'], '', $string);
} }
@@ -243,7 +249,7 @@ class Str
{ {
$str = ''; $str = '';
if (!$requestTime) { if (!$requestTime) {
$requestTime = microtime(true); $requestTime = microtime(TRUE);
} }
$_user = str_split(md5($user . md5((string)$user))); $_user = str_split(md5($user . md5((string)$user)));
ksort($_user); ksort($_user);
@@ -268,7 +274,7 @@ class Str
* @param bool $unfairest * @param bool $unfairest
* @return string * @return string
*/ */
public static function convertUnderline(string $str, bool $unfairest = true): string public static function convertUnderline(string $str, bool $unfairest = TRUE): string
{ {
$str = ucwords(str_replace('_', ' ', $str)); $str = ucwords(str_replace('_', ' ', $str));
$str = str_replace(' ', '', lcfirst($str)); $str = str_replace(' ', '', lcfirst($str));