|
@@ -982,4 +982,72 @@ if(!function_exists('birthtime_to_age')) {
|
|
|
|
|
|
return $age;
|
|
|
}
|
|
|
+}
|
|
|
+
|
|
|
+if (!function_exists('unix_time')) {
|
|
|
+ /**
|
|
|
+ * 格式化
|
|
|
+ * @param $time
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ function unix_time($time): string
|
|
|
+ {
|
|
|
+ //获取今天凌晨的时间戳
|
|
|
+ $day = strtotime(date('Y-m-d', time()));
|
|
|
+ //获取昨天凌晨的时间戳
|
|
|
+ $pday = strtotime(date('Y-m-d', strtotime('-1 day')));
|
|
|
+ //获取现在的时间戳
|
|
|
+ $nowtime = time();
|
|
|
+ $t = $nowtime - $time;
|
|
|
+ if ($time < $pday) {
|
|
|
+ $str = date('m-d', $time);
|
|
|
+ } elseif ($time < $day && $time > $pday) {
|
|
|
+ $str = "昨天";
|
|
|
+ } elseif ($t > 60 * 60) {
|
|
|
+ $str = floor($t / (60 * 60)) . "小时前";
|
|
|
+ } elseif ($t > 60) {
|
|
|
+ $str = floor($t / 60) . "分钟前";
|
|
|
+ } else {
|
|
|
+ $str = "刚刚";
|
|
|
+ }
|
|
|
+ return $str;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 多行输入框回车换行
|
|
|
+ * @param string $str
|
|
|
+ * @return string mixed
|
|
|
+ */
|
|
|
+if (!function_exists('line_feed')) {
|
|
|
+ function line_feed(string $str): string
|
|
|
+ {
|
|
|
+ return str_replace("\n", "<br />", $str ?? '');
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+if (!function_exists('str_limit')){
|
|
|
+ /**
|
|
|
+ * 超出字符省略
|
|
|
+ * @param $value
|
|
|
+ * @param int $limit
|
|
|
+ * @param string $end
|
|
|
+ * @return mixed|string
|
|
|
+ */
|
|
|
+ function str_limit($value, int $limit = 100, string $end = '...') {
|
|
|
+ if (mb_strwidth($value, 'UTF-8') <= $limit) {
|
|
|
+ return $value;
|
|
|
+ }
|
|
|
+ return rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8')) . $end;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+if (!function_exists('dd')) {
|
|
|
+ function dd(...$vars){
|
|
|
+ foreach ($vars as $v) {
|
|
|
+ dump($v);
|
|
|
+ }
|
|
|
+ exit();
|
|
|
+ }
|
|
|
}
|