2
0
Эх сурвалжийг харах

给simplexml_load_string 增加错误处理

visuddhinanda 2 жил өмнө
parent
commit
832cad5336

+ 19 - 4
app/Http/Api/MdRender.php

@@ -36,7 +36,12 @@ class MdRender{
         return $html;
     }
     public static function xmlQueryId(string $xml, string $id):string{
-        $dom = simplexml_load_string($xml);
+        try{
+            $dom = simplexml_load_string($xml);
+        }catch(\Exception $e){
+            Log::error($e);
+            return "<div></div>";
+        }
         $tpl_list = $dom->xpath('//MdTpl');
         foreach ($tpl_list as $key => $tpl) {
             foreach ($tpl->children() as  $param) {
@@ -57,7 +62,12 @@ class MdRender{
     }
     public static function take_sentence(string $xml):array{
         $output = [];
-        $dom = simplexml_load_string($xml);
+        try{
+            $dom = simplexml_load_string($xml);
+        }catch(\Exception $e){
+            Log::error($e);
+            return $output;
+        }
         $tpl_list = $dom->xpath('//MdTpl');
         foreach ($tpl_list as $key => $tpl) {
             foreach($tpl->attributes() as $a => $a_value){
@@ -85,8 +95,13 @@ class MdRender{
          * 获取模版参数
          * 生成react 组件参数
          */
-        //$xml = str_replace(['<b>','</b>'],['',''],$xml);
-        $dom = simplexml_load_string($xml);
+        try{
+            $dom = simplexml_load_string($xml);
+        }catch(\Exception $e){
+            Log::error($e);
+            return "<span></span>";
+        }
+
 
         $tpl_list = $dom->xpath('//MdTpl');
         foreach ($tpl_list as $key => $tpl) {