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;
$default = self::STRING . strtoupper(self::STRING) . self::NUMBER;
$default = str_split($default);
$string .= str_repeat($default[array_rand($default)], $length);
return (string)$string;
for ($i = 0; $i < $length; $i++) {
shuffle($default);
$string .= $default[array_rand($default)];
}
return $string;
}
/**
@@ -45,7 +48,10 @@ class Str
$number = '';
$default = str_split(self::NUMBER);
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;
}
@@ -57,7 +63,7 @@ class Str
*
* @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) {
$string = strip_tags($string);
@@ -83,10 +89,10 @@ class Str
* @return bool
* 判断是否为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);
if ($json && is_callable($callback, true)) {
if ($json && is_callable($callback, TRUE)) {
return call_user_func($callback, $data);
}
return $json;
@@ -99,10 +105,10 @@ class Str
* @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;
if ($false && is_callable($callBack, true)) {
$false = !empty($data) && swoole_unserialize($data) !== FALSE;
if ($false && is_callable($callBack, TRUE)) {
return call_user_func($callBack, $data);
}
return $false;
@@ -184,7 +190,7 @@ class Str
* @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());
@@ -227,7 +233,7 @@ class Str
public static function clear(string $string): array|string|null
{
$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 = '';
if (!$requestTime) {
$requestTime = microtime(true);
$requestTime = microtime(TRUE);
}
$_user = str_split(md5($user . md5((string)$user)));
ksort($_user);
@@ -268,7 +274,7 @@ class Str
* @param bool $unfairest
* @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 = str_replace(' ', '', lcfirst($str));