# 모든 태그 제거
$strContents = preg_replace("(\<(/?[^\>]+)\>)", "", $strContents);
# 한칸 이상 공백 제거
$strContents = preg_replace("/\s{2,}/"," ",$strContents);
# 탭키 제거
$strContents = str_replace("\t", "", $strContents);
# `
$strContents = str_replace("'", "`", $strContents);
#  
$strContents = str_replace(" ", " ", $strContents);
1번째 코드 주로 사용하나, 가끔 공백(탭)이 제거가 안된다.
$strBody = str_replace("\r", "", str_replace("\n", "", $strBody));
str_replace 대신 preg_reaplce를 사용하여 다시 제거해본다.
$strBody = preg_replace('/\r\n|\r|\n/','',$strBody);
안되어서 탭키를 따로 제거해주었다.
$strBody=str_replace("\t", "", $strBody);
공백제거 모음
# 공백제거 추가 2022.04.06
$strContents = preg_replace("/\s{2,}/"," ",$strContents);
$strContents = str_replace("\t", "", $strContents);
$strContents = str_replace("\r", "", str_replace("\n", "", $strContents));
$strContents = preg_replace('/\r\n|\r|\n/','',$strContents);
기타 공백제거 코드
$strBody=str_replace(" "," ",$strBody);
$strBody=str_replace("\n", "", $strBody);
'Development > PHP' 카테고리의 다른 글
[정규표현식] 정규식 문자열 제거(영문/숫자) (0) | 2021.12.28 |
---|---|
정규식 html 태그제거 (0) | 2021.12.28 |
인코딩 깨질 때 (0) | 2021.12.23 |
[Crawler] post 방식의 json 파싱 (0) | 2021.12.23 |
PHP 인젝션 (0) | 2021.12.20 |