Development/PHP
정규표현식 - 특정 HTML 태그 제거하기
곽진돔
2022. 1. 12. 14:24
해당 태그 및 태그의 내용을 모두 제거한다.
#style 태그 제거
$strContents = preg_replace('@<style(.*?)[[:space:]](.*?)</style>@i', '', $strContents);
#script 태그 제거
$strContents = preg_replace('@<script(.*?)[[:space:]](.*?)</script>@i', '', $strContents);
# p태그 추출
preg_match_all('@<p>(.*?)[[:space:]](.*?)</p>@i',$strContents,$arrContents, PREG_PATTERN_ORDER);
# 추출 후 합치기
$strContents = implode(" ",$arrContents[0]);