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} + - + - +