作者 邓超

x

@@ -298,7 +298,8 @@ class Home extends Base { @@ -298,7 +298,8 @@ class Home extends Base {
298 $sendData['receipt'] = empty($formData['receipt']) ? '' : 1;// 回执,阅读后收回执的邮箱 298 $sendData['receipt'] = empty($formData['receipt']) ? '' : 1;// 回执,阅读后收回执的邮箱
299 $sendData['priority'] = $formData['priority']??3;// 是否紧急邮件 299 $sendData['priority'] = $formData['priority']??3;// 是否紧急邮件
300 $sendData['subject'] = $formData['subject'];// //Content 主题,标题 300 $sendData['subject'] = $formData['subject'];// //Content 主题,标题
301 - $sendData['body'] = $formData['body']; 301 + // 删除script标记
  302 + $sendData['body'] = strip_tags_content($formData['body'],'<script>',true);
302 // 不重要的信息 303 // 不重要的信息
303 $sendData['jobName'] = $formData['jobName']??'';//任务标题 304 $sendData['jobName'] = $formData['jobName']??'';//任务标题
304 $sendData['massSuit'] = $formData['massSuit']??0;// 是否是群发单显 305 $sendData['massSuit'] = $formData['massSuit']??0;// 是否是群发单显
@@ -400,7 +400,46 @@ function paramHas(string $name):bool { @@ -400,7 +400,46 @@ function paramHas(string $name):bool {
400 } 400 }
401 401
402 402
  403 +/**
  404 + * Sample text:
  405 + $text = '<b>sample</b> text with <div>tags</div>';
  406 +
  407 + Result for strip_tags($text):
  408 + sample text with tags
  409 +
  410 + Result for strip_tags_content($text):
  411 + text with
403 412
  413 + Result for strip_tags_content($text, '<b>'):
  414 + <b>sample</b> text with
404 415
  416 + Result for strip_tags_content($text, '<b>', TRUE);
  417 + text with <div>tags</div>
  418 +
  419 + I hope that someone is useful :)
  420 + * 删除html标记
  421 + * @param $text
  422 + * @param string $tags
  423 + * @param false $invert
  424 + * @return string|string[]|null
  425 + * @author:dc
  426 + * @time 2023/6/20 18:05
  427 + */
  428 +function strip_tags_content($text, $tags = '', $invert = FALSE) {
  429 + preg_match_all('/<(.+?)[\s]*\/?[\s]*>/si', trim($tags), $tags);
  430 + $tags = array_unique($tags[1]);
  431 + if(is_array($tags) AND count($tags) > 0) {
  432 + if($invert == FALSE) {
  433 + return preg_replace('@<(?!(?:'. implode('|', $tags) .')\b)(\w+)\b.*?>.*?</\1>@si', '', $text);
  434 + }
  435 + else {
  436 + return preg_replace('@<('. implode('|', $tags) .')\b.*?>.*?</\1>@si', '', $text);
  437 + }
  438 + }
  439 + elseif($invert == FALSE) {
  440 + return preg_replace('@<(\w+)\b.*?>.*?</\1>@si', '', $text);
  441 + }
  442 + return $text;
  443 +}
405 444
406 445