|
@@ -6178,9 +6178,23 @@ class NewsService implements NewsServiceInterface
|
|
|
$data['keyword'] = implode(',', $segList1);
|
|
|
}
|
|
|
if ($data['description'] == '') {
|
|
|
- //提取内容中的描述
|
|
|
- // var_dump(11111);
|
|
|
- $data['description'] = mb_substr(str_replace(' ', '', strip_tags($data['introduce'])), 0, 100);
|
|
|
+ //提取内容中的描述
|
|
|
+ // var_dump(11111);
|
|
|
+ //提取内容中的描述
|
|
|
+ $content = $data['introduce'];
|
|
|
+ // 去除 <style> 和 <script> 标签及其内容
|
|
|
+ $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
|
|
|
+ // 去除所有 HTML 标签
|
|
|
+ $content = strip_tags($content);
|
|
|
+ // 去除 HTML 实体
|
|
|
+ $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
|
|
|
+ // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
|
|
|
+ $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
|
|
|
+ // 去除多余空白
|
|
|
+ $content = preg_replace('/\s+/u', '', $content);
|
|
|
+ // 截取 100 个字符
|
|
|
+ $data['description'] = mb_substr($content, 0, 100);
|
|
|
+ // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
|
|
|
}
|
|
|
$project = Project::insertGetId($data);
|
|
|
if (empty($project)) {
|
|
@@ -6222,9 +6236,23 @@ class NewsService implements NewsServiceInterface
|
|
|
$data['keyword'] = implode(',', $segList1);
|
|
|
}
|
|
|
if ($data['description'] == '') {
|
|
|
- //提取内容中的描述
|
|
|
- // var_dump(11111);
|
|
|
- $data['description'] = mb_substr(str_replace(' ', '', strip_tags($data['introduce'])), 0, 100);
|
|
|
+ //提取内容中的描述
|
|
|
+ // var_dump(11111);
|
|
|
+ //提取内容中的描述
|
|
|
+ $content = $data['introduce'];
|
|
|
+ // 去除 <style> 和 <script> 标签及其内容
|
|
|
+ $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
|
|
|
+ // 去除所有 HTML 标签
|
|
|
+ $content = strip_tags($content);
|
|
|
+ // 去除 HTML 实体
|
|
|
+ $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
|
|
|
+ // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
|
|
|
+ $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
|
|
|
+ // 去除多余空白
|
|
|
+ $content = preg_replace('/\s+/u', '', $content);
|
|
|
+ // 截取 100 个字符
|
|
|
+ $data['description'] = mb_substr($content, 0, 100);
|
|
|
+ // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
|
|
|
}
|
|
|
$result = Project::where('id', $id)->update($data);
|
|
|
if (empty($result)) {
|