|
@@ -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
|
|