Browse Source

修改描述

rkljw 3 days ago
parent
commit
95567a7554
1 changed files with 8 additions and 3 deletions
  1. 8 3
      app/JsonRpc/NewsService.php

+ 8 - 3
app/JsonRpc/NewsService.php

@@ -475,7 +475,10 @@ class NewsService implements NewsServiceInterface
       }
       if ($articleData['introduce'] == '') {
         //提取内容中的描述
-        $articleData['introduce'] = substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
+        $content = preg_replace('/<style\b[^>]*>(.*?)<\/style>/is', '', $data['content']);
+        $content = strip_tags($content);
+        $content = str_replace(' ', '', $content);
+        $articleData['introduce'] = mb_substr($content, 0, 100);
       }
 
       $id = Article::insertGetId($articleData);
@@ -646,8 +649,10 @@ class NewsService implements NewsServiceInterface
       }
       if ($articleData['introduce'] == '') {
         //提取内容中的描述
-        $articleData['introduce'] = substr(preg_replace('/\s+/', '', strip_tags($data['content'])), 0, 100);
-        // substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
+        $content = preg_replace('/<style\b[^>]*>(.*?)<\/style>/is', '', $data['content']);
+        $content = strip_tags($content);
+        $content = str_replace(' ', '', $content);
+        $articleData['introduce'] = mb_substr($content, 0, 100);
       }
 
       $id = Article::where(['id' => $data['id']])->update($articleData);