Development/PHP

정규식 html 태그제거

곽진돔 2021. 12. 28. 16:18

preg_replace() 함수를 이용해서 정규식 치환하기
 

$strContent = preg_replace("(\<(/?[^\>]+)\>)", "", $strContent);

 
 

# 모든 태그 제거 ( 공백으로 치환)
$strContents_cp = preg_replace("(\<(/?[^\>]+)\>)", " ", $strContents_cp);

# 치환 후 공백제거(2칸 이상인 공백 한칸으로 변경)
$strContents_cp = preg_replace("/\s{2,}/"," ",$strContents_cp);