게시판에서 본문 요약문을 뽑아올 때 getSummary 함수를 씁니다.
찾아보니 얘는 getContent 함수를 참조하더군요.
제 경우, 관리자 계정으로 들어가 본문 내에 이미지만 넣고 style 태그나 script 태그만 삽입하는 경우가 있습니다.
이때 게시판 목록에서 getSummary로 요약문을 출력하면 style과 script가 strip_tags만 적용돼서 style 태그나 script 태그 안의 내용이 그대로 노출되는 경우가 있습니다.
그래서 getContent 함수에서 다음과 같은 정규표현식으로 본문 내의 style과 script를 제거해봤습니다.
$content = $this->get('content');
if(!$stripEmbedTagException) stripEmbedTagForAdmin($content, $this->get('member_srl'));
$content = preg_replace('/<style\\b[^>]*>(.*?)<\\/style>/is', '', $content);
$content = preg_replace('/<script\\b[^>]*>(.*?)<\\/style>/is', '', $content);
if(!$stripEmbedTagException) stripEmbedTagForAdmin($content, $this->get('member_srl'));
$content = preg_replace('/<style\\b[^>]*>(.*?)<\\/style>/is', '', $content);
$content = preg_replace('/<script\\b[^>]*>(.*?)<\\/style>/is', '', $content);
일단 아직까지는 별 무리 없이, 깨끗하게 정말로 plain한 텍스트만 출력이 되고 있는데요.
... 이렇게 해도 무방한가요?

윤삼
Lv. 19
아무래도 중급 초반 수준의 코딩 오타쿠인 것 같습니다.
댓글 7
아악, 복붙하다가 실수가 있었어요 :*
암튼 이런 방식으로 해도 문제 없나요?
고려해야 하는게 좀 더 있긴 합니다만, 관리자용일테니 문제되진 않겠죠.
$content = preg_replace('/<\!--(.*)-->/is', '', $content);
$content = str_replace('<script', '<!--', $content);
$content = str_replace('</script>', '-->', $content);
$content = str_replace('<style', '<!--', $content);
$content = str_replace('</style>', '-->', $content);
$content = strip_tags($content);
오오, 제가 한 것처럼 한꺼번에 제외시키는 것보다 엔데벨님 말씀처럼 하는 게 더 깔끔한 건가요?
본문에서도 태그가 사라지는 문제가 있었네요;;;
게시판 리스트에서만 style, script 태그를 제거하도록 다음과 같이 했습니다.
if(!$stripEmbedTagException) stripEmbedTagForAdmin($content, $this->get('member_srl'));
if(!Context::get('document_srl'))
{
$content = preg_replace('/<style\\b[^>]*>(.*?)<\\/style>/is', '', $content);
$content = preg_replace('/<script\\b[^>]*>(.*?)<\\/script>/is', '', $content);
}