정규식 특수문자 PHP
2013/04/26 13:29
http://blog.naver.com/mylovejam/100186746366
전용뷰어 보기
function ptrtxt($str)
{
preg_match_all('!['
.'\x{1100}-\x{11FF}\x{3130}-\x{318F}\x{AC00}-\x{D7AF}'
.'\x{2E80}-\x{2EFF}' // 한,중,일 부수 보충
.'\x{31C0}-\x{31EF}\x{3200}-\x{32FF}'
.'\x{3400}-\x{4DBF}\x{4E00}-\x{9FBF}\x{F900}-\x{FAFF}'
.'\x{20000}-\x{2A6DF}\x{2F800}-\x{2FA1F}'// 한,중,일 호환한자
.'a-zA-Z'
.'\x{3040}-\x{309F}'// 히라가나
.'\x{30A0}-\x{30FF}'// 가타카나
.'\x{31F0}-\x{31FF}'// 가타카나 음성 확장
.'\s'
.']+!u', $str, $match);
return implode('',$match[0]);
}
$content = "【CD】Juniel(ジュニエル) - Fall In L";
echo ptrtxt($content);
결과 CDJunielジュニエル Fall In L
=========================================================================================================
\x{1100}-\x{11FF} // 한글 자모 (Hangul Jamo)
\x{3130}-\x{318F} // 호환용 한글 자모 (Hangul Compatibility Jamo)
\x{AC00}-\x{D7AF} // 한글 소리 마디 (Hangul Syllables)
if ( preg_match('/[\x{1100}-\x{11FF}\x{3130}-\x{318F}\x{AC00}-\x{D7AF}]+/u',$변수) ) exit('한글이 포함됨');
=========================================================================================================
문자열이 utf-8로 인코딩되어있다고 가정합니다. 따라서 utf-8을 사용하고 있지 않다면 이 함수를 사용하기 전에 iconv 등을 이용해서 인코딩을 utf-8로 변경해주셔야 합니다.
function onlyHanAlpha($subject) {
$pattern = '/([\xEA-\xED][\x80-\xBF]{2}|[a-zA-Z])+/';
preg_match_all($pattern, $subject, $match);
return implode('', $match[0]);
}
$subject = '한글입니다.옆은 일본어日本最大級일본최대급?!@#!asdf91237 ad한글%#@$하하하^%&({}as23寒한문';
echo $subject;
echo "\n";
echo onlyHanAlpha($subject);
=========================================================================================================
유니코드 특수 문자제거
http://jrgraphix.net/r/Unicode/1720-173F
유니코드에서 Geometric Shapes 와 Miscellaneous Symbols만 막으면 되겠네요
코드는 25A0-25FF 2600-26FF까지
preg_replace('/[\25a0-\25ff][\2600-\26ff\]/', '', $str);
=========================================================================================================
$alphabet = 'A-Za-z';
$hangul_jamo = '\x{1100}-\x{11ff}';
$hangul_compatibility_jamo = '\x{3130}-\x{318f}';
$hangul_syllables = '\x{ac00}-\x{d7af}';
$cnt = preg_match_all('/['.$alphabet.$hangul_jamo.$hangul_compatibility_jamo.$hangul_syllables.']+/u', $utf8text, $matches);
print_r($matches);
'PHP∵SCRIPT' 카테고리의 다른 글
PHP에서 특수문자 없애는 정규표현식 (0) | 2013.12.31 |
---|---|
정규식, 특수문자 입력 제한 (0) | 2013.12.31 |
preg_match 검색대상에 엔터가 들어간경우는 검색옵션에 s 를 추가하라. (0) | 2013.12.31 |
php 정규식 종류별 문자 추출 (0) | 2013.12.31 |
영문자로만 되어 있는지 (0) | 2013.12.31 |
문자열에서 영문+숫자만추출하기 (0) | 2013.12.31 |
번호 시작 1. tets 2.tets 11.test 추출 정렬 처리 (0) | 2013.12.31 |
내용중 image 추출 처리 (0) | 2013.12.31 |
댓글