|
@@ -475,9 +475,18 @@ class NewsService implements NewsServiceInterface
|
|
|
}
|
|
|
if ($articleData['introduce'] == '') {
|
|
|
//提取内容中的描述
|
|
|
- $content = preg_replace('/<style\b[^>]*>(.*?)<\/style>/is', '', $data['content']);
|
|
|
+ $content = $data['content'];
|
|
|
+ // 去除 <style> 和 <script> 标签及其内容
|
|
|
+ $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
|
|
|
+ // 去除所有 HTML 标签
|
|
|
$content = strip_tags($content);
|
|
|
- $content = str_replace(' ', '', $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 个字符
|
|
|
$articleData['introduce'] = mb_substr($content, 0, 100);
|
|
|
}
|
|
|
|
|
@@ -649,9 +658,18 @@ class NewsService implements NewsServiceInterface
|
|
|
}
|
|
|
if ($articleData['introduce'] == '') {
|
|
|
//提取内容中的描述
|
|
|
- $content = preg_replace('/<style\b[^>]*>(.*?)<\/style>/is', '', $data['content']);
|
|
|
+ $content = $data['content'];
|
|
|
+ // 去除 <style> 和 <script> 标签及其内容
|
|
|
+ $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
|
|
|
+ // 去除所有 HTML 标签
|
|
|
$content = strip_tags($content);
|
|
|
- $content = str_replace(' ', '', $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 个字符
|
|
|
$articleData['introduce'] = mb_substr($content, 0, 100);
|
|
|
}
|
|
|
|
|
@@ -5786,7 +5804,19 @@ class NewsService implements NewsServiceInterface
|
|
|
}
|
|
|
if ($data['introduce'] == '' || empty($data['introduce'])) {
|
|
|
//提取内容中的描述
|
|
|
- $data['introduce'] = mb_substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100) ?? '';
|
|
|
+ $content = $data['content'];
|
|
|
+ // 去除 <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['introduce'] = mb_substr($content, 0, 100);
|
|
|
}
|
|
|
$user = User::where('id', $data['user_id'])->first();
|
|
|
if (empty($user)) {
|
|
@@ -5842,8 +5872,19 @@ class NewsService implements NewsServiceInterface
|
|
|
}
|
|
|
if ($data['introduce'] == '') {
|
|
|
//提取内容中的描述
|
|
|
- // var_dump(11111);
|
|
|
- $data['introduce'] = mb_substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
|
|
|
+ $content = $data['content'];
|
|
|
+ // 去除 <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['introduce'] = mb_substr($content, 0, 100);
|
|
|
}
|
|
|
if (isset($data['level']) && $data['level'] != null) {
|
|
|
$data['level'] = intval($data['level']);
|