From fa84c4989ee2847d6f83a9fe67d45dbdc296034f Mon Sep 17 00:00:00 2001 From: xiaodong Date: Mon, 7 Sep 2026 09:18:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=B4=E9=83=A8=E6=8A=96=E9=9F=B3=E5=BE=AE?= =?UTF-8?q?=E5=8D=9A=E7=9F=A5=E4=B9=8E=E9=93=BE=E6=8E=A5=E5=81=9A=E6=B4=BB?= =?UTF-8?q?,=E5=8F=AF=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common.php | 36 ++++++++++++++++++++++ .../website/1/zh/demo/components/header.html | 12 ++++++-- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/app/common.php b/app/common.php index 6f965b1..29ba2fc 100644 --- a/app/common.php +++ b/app/common.php @@ -1695,3 +1695,39 @@ if (!function_exists('getChildCategoriesContent')) { } } } + +// 函数名:getDescriptionSeparate (查询表 hc_category 中的字段 description 根据这个字段拆分成数组返回) +// 传入 cate_id 和 separate_str, 注意为空的判断; +if (!function_exists('getDescriptionSeparate')) { + function getDescriptionSeparate($cate_id) + { + if (empty($cate_id)) { + return []; + } + + try { + $description = \think\facade\Db::table('hc_category') + ->where('id', $cate_id) + ->value('description'); + + if (empty($description)) { + return []; + } + + // 使用正则提取所有以 http:// 或 https:// 开头的链接 + // 匹配规则:以http(s)开头,直到遇到空白符或中文字符"分隔符"为止 + preg_match_all('/https?:\/\/[^\s分隔符]+/', $description, $matches); + + $result = $matches[0] ?? []; + + // 过滤空值并重新索引 + $result = array_filter($result, function ($value) { + return !empty(trim($value)); + }); + + return array_values($result); + } catch (\Exception $e) { + return []; + } + } +} diff --git a/public/themes/website/1/zh/demo/components/header.html b/public/themes/website/1/zh/demo/components/header.html index 7a664a4..a73116d 100644 --- a/public/themes/website/1/zh/demo/components/header.html +++ b/public/themes/website/1/zh/demo/components/header.html @@ -62,7 +62,13 @@ 官方微信 - + {php} + $content_arr = getDescriptionSeparate(707); + $douyin_url = $content_arr['0'] ?? ''; + $sina_url = $content_arr['1'] ?? ''; + $zhihu_url = $content_arr['2'] ?? ''; + {/php} + - + - +