The current possible PCRE modifiers are listed below. The names in
parentheses refer to internal PCRE names for these modifiers. Spaces and
newlines are ignored in modifiers, other characters cause error.
i (PCRE_CASELESS)
If this modifier is set, letters in the pattern match both upper and lower case letters.
m (PCRE_MULTILINE)
By default, PCRE treats the subject string as consisting of a single "line" of characters (even if it actually contains several newlines). The "start of line" metacharacter (^) matches only at the start of the string, while the "end of line" metacharacter ($) matches only at the end of the string, or before a terminating newline (unless D modifier is set). This is the same as Perl. When this modifier is set, the "start of line" and "end of line" constructs match immediately following or immediately before any newline in the subject string, respectively, as well as at the very start and end. This is equivalent to Perl's /m modifier. If there are no "\n" characters in a subject string, or no occurrences of ^ or $ in a pattern, setting this modifier has no effect.
s (PCRE_DOTALL)
If this modifier is set, a dot metacharacter in the pattern matches all characters, including newlines. Without it, newlines are excluded. This modifier is equivalent to Perl's /s modifier. A negative class such as [^a] always matches a newline character, independent of the setting of this modifier.
x (PCRE_EXTENDED)
If this modifier is set, whitespace data characters in the pattern are totally ignored except when escaped or inside a character class, and characters between an unescaped # outside a character class and the next newline character, inclusive, are also ignored. This is equivalent to Perl's /x modifier, and makes it possible to include comments inside complicated patterns. Note, however, that this applies only to data characters. Whitespace characters may never appear within special character sequences in a pattern, for example within the sequence (?( which introduces a conditional subpattern.
e (PREG_REPLACE_EVAL)
If this modifier is set, preg_replace() does normal substitution of backreferences in the replacement string, evaluates it as PHP code, and uses the result for replacing the search string. Single quotes, double quotes, backslashes and NULL chars will be escaped by backslashes in substituted backreferences.
Only preg_replace() uses this modifier; it is ignored by other PCRE functions.
A (PCRE_ANCHORED)
If this modifier is set, the pattern is forced to be "anchored", that is, it is constrained to match only at the start of the string which is being searched (the "subject string"). This effect can also be achieved by appropriate constructs in the pattern itself, which is the only way to do it in Perl.
D (PCRE_DOLLAR_ENDONLY)
If this modifier is set, a dollar metacharacter in the pattern matches only at the end of the subject string. Without this modifier, a dollar also matches immediately before the final character if it is a newline (but not before any other newlines). This modifier is ignored if m modifier is set. There is no equivalent to this modifier in Perl.
S
When a pattern is going to be used several times, it is worth spending more time analyzing it in order to speed up the time taken for matching. If this modifier is set, then this extra analysis is performed. At present, studying a pattern is useful only for non-anchored patterns that do not have a single fixed starting character.
U (PCRE_UNGREEDY)
This modifier inverts the "greediness" of the quantifiers so that they are not greedy by default, but become greedy if followed by "?". It is not compatible with Perl. It can also be set by a (?U) modifier setting within the pattern or by a question mark behind a quantifier (e.g. .*?).
X (PCRE_EXTRA)
This modifier turns on additional functionality of PCRE that is incompatible with Perl. Any backslash in a pattern that is followed by a letter that has no special meaning causes an error, thus reserving these combinations for future expansion. By default, as in Perl, a backslash followed by a letter with no special meaning is treated as a literal. There are at present no other features controlled by this modifier.
J (PCRE_INFO_JCHANGED)
The (?J) internal option setting changes the local PCRE_DUPNAMES option. Allow duplicate names for subpatterns.
u (PCRE_UTF8)
This modifier turns on additional functionality of PCRE that is incompatible with Perl. Pattern strings are treated as UTF-8. This modifier is available from PHP 4.1.0 or greater on Unix and from PHP 4.2.3 on win32. UTF-8 validity of the pattern is checked since PHP 4.3.5.
preg_match
(PHP 4, PHP 5)
preg_match -- 정규표현식 매치를 수행합니다.
설명
int preg_match ( string $pattern, string $subject [, array
$matches [, int $flags [, int $offset]]] )
pattern에 주어진 정규표현식을 subject에서 찾습니다.
matches가 주어지면, 검색 결과를 채워넣습니다. $matches[0]는 전체 패턴
텍스트가 들어가고, $matches[1]부터 괄호로 둘러싸인 서브 패턴을 채워넣습니다.
flags는 다음과 같은 플래그를 사용할 수 있습니다:
PREG_OFFSET_CAPTURE
이 플래그를 넘기면, 모든 매치에 대한 문자열 시작 위치를 함께 반환합니다. 반환값을 0에 매치한 문자열을 가지고,
1에 문자열 시작 위치를 가지는 배열을 원소로 갖는 배열로 변경하는 점에 주의하십시오. 이 플래그는
PHP 4.3.0부터 사용할 수 있습니다.
flags 인자는
PHP 4.3.0부터 사용할 수 있습니다.
보통, 검색은 목표 문자열의 처음에서 시작합니다. 선택적인 인자 offset으로 검색을 시작할 다른 위치를
지정할 수 있습니다. 이는 preg_match()의 목표 문자열에 substr()($subject, $offset)을 넘기는 것과 동일합니다.
offset 인자는 PHP 4.3.3부터 사용할 수 있습니다.
preg_match()는 pattern이 매치된 횟수를 반환합니다. 이는 0(매치 없음)이나
1입니다. preg_match()는 처음 매치 후에 검색을 중지하기 때문입니다. 대조적으로, preg_match_all()는
subject의 끝까지 계속해서 실행합니다. 에러가 발생하면, preg_match()는
FALSE를 반환합니다.
작은 정보
단순히 하나의 문자열이 다른 문자열에 들어있는지를 확인하고 싶을때는 preg_match()를 사용하지 마십시오. 대신, strpos()나 strstr()를 사용하는 편이 더욱 빠릅니다.
예 1620. 문자열 "php" 찾기
<?php // 패턴 구분자 뒤의 "i"는 대소문자를 구별하지 않게 합니다. if (preg_match("/php/i", "PHP is the web scripting language of choice.")) {
echo "발견하였습니다.";
} else {
echo "발견하지 못했습니다.";
} ?>
예 1621. 단어 "Web" 찾기
<?php /* 패턴에서 \b는 단어를 지시합니다. 단어 "web"만 매치하고,
* "webbing"이나 "cobweb" 등의 부분적인 경우에는 매치하지 않습니다. */ if (preg_match("/\bweb\b/i", "PHP is the web scripting language of choice.")) {
echo "발견하였습니다.";
} else {
echo "발견하지 못했습니다.";
}
if (preg_match("/\bweb\b/i", "PHP is the website scripting language of choice.")) {
echo "발견하였습니다.";
} else {
echo "발견하지 못했습니다.";
} ?>
예 1622. URL에서 도메인 이름 얻기
<?php // URL에서 호스트 이름 얻기 preg_match("/^(http:\/\/)?([^\/]+)/i", "http://www.php.net/index.html", $matches); $host = $matches[2];
// 호스트 이름에서 마지막 두 세그멘트 얻기 preg_match("/[^\.\/]+\.[^\.\/]+$/", $host, $matches);
echo "도메인 이름은: {$matches[0]}\n"; ?>
1. freetds 0.51 을 이용한 방법 - 한글문제가 아직 해결이 안되었다
2. Sybase Client Library - php 컴파일할 때 .h 파일이 없다
3. odbc 를 이용한 방법
입니다.
이중 freetds 를 이용한 방법은 요 아래글에 정진석님이라는 분이 아주 잘 정리한 글이 있습니다. 고걸 보세요..
요거는 odbc 를 통하지 않기 때문에 속도도 빠르고 다 좋지만 한글이 완벽히 해결이 안되어 있습니다. 한글만 해결하면 젤 좋은거 같습니다.
한글땜에 전 두번째 방법을 시도 했었죠......
sybase-common-11.9.2-3.i386.rpm 파일을 받아다 썼는데...
근데...애는 필요한 파일이 다 없더군요.. 찾아보니 freetds 에 필요한 헤더파일이 있기에 걍 카피해다가 썼는데 apachectl 이 아예 실행이 되질 않습니다. 이것저것 보다가 요것두 포기했습니다.
드뎌 3번째 odbc....... 흐흐~
요건 성공했슴다... 하지만 속도가 훨 느립니다... 하지만 현재로서는 이 방법이 최선인듯 보입니다..
아래 설명 들어갑니다.
<ODBC 를 이용한 방법>
A. 프로그램 다운로드
i. 리눅스용 odbc 드라이버 (install.sh l2oczzzz.taz) www.openlinksw.com 에서 받는다. 등록하면 무료로 받을 수 있다.
ii. Windows용 리퀘스트 브로커 (ntadmzzz.zip)
위에꺼와 같이 받을 수 있다. 다른 기종에서 mssql로 연결할 때 중간에서 해주는 넘이다
iii. iodbc SDK (libiodbc-2.50.3.tar.gz) www.iodbc.org 에서 받는다. php 컴파일할 때 필요하다
B. Windows쪽 설치 (물론 sql7서버는 이미 설치되어 있어야 겠죵~)
i. ntadmzzz.zip 을 적당한곳에서 푼다
ii. disk1 에 있는 setup.exe 을 실행한다
iii. 설치중에 적당히 설정을 조정한다 (기본 설정 써도 무난)
iv. 재부팅하면 자동으로 서비스가 실행된다.
v. openlink 가 설치된 폴더에 있는 udbc.ini 는 리눅스쪽에서 필요하니 따로 카피를 해 놓는다
C. 리눅스쪽 설치
i. 다음 과정을 한다
#mkdir /usr/local/openlink
#install.sh 와 l2oczzzz.taz 를 /usr/local/openlink 에 복사
#cd /usr/local/openlink
#./install.sh
압축을 풀면서 설치한다. 중간에 두번 물어보는데 root 라고 만 치면 된다
# cp windows에서얻어온udbc.ini bin/
bin 디렉토리에는 odbc.ini odbcinst.ini 도 함께 있다
#./openlink.sh를 실행하면 필요한 환경변수가 잡힌다
안잡히면 수동으로라도 해 주세요.....
ii. odbc.ini odbcinst.ini 에서 경로부분을 /home 에서 /usr/local 로 맞게 모두 수정한다
iii. udbc.ini 에 있는 예제 dsn_sql6 부분을 odbc.ini 으로 카피한 다음 아래처럼 수정한다
[ODBC Data Sources] à 요기는 리스트만 보여줄뿐 없어도 된다
OpenLink = 어쩌고 저쩌고 (원래 있는 부분)
healingmall = healingmall mssql7 Server
최근에 다시 freetds 를 이용한 방법으로 한글문제까지 깔끔히 해결을 해서 이렇게 다시 글을 답니다.....
다른 분들이 올려놓은 글들이 많은 도움이 되었습니다....
openlink 보다 freetds를 쓰면 좋은점....
1. 훨 빠르당
2. 윈도우쪽은 전혀 건들지 않아도 된다. (리퀘스트브로커 같은거 안깔아두 된다)
3. php 에서 top 이라든가 distinct 등의 구문이 먹지 않는데 freetds 는 아무 문제가 없다... 등등입니다..
어떻게 한글을 해결했나...
1. tdsver 를 7.0을 쓰는게 아니구 4.2를 씁니다...
2. 원래 4.2는 sql 6.5 시절에 쓰던건데 sql 7.0 이나 sql 2000 에서 써두 암 문제 없당..
3. sql 쪽에서 컬럼타입을 잡을때 varchar 대신 nvarchar 같은 unicode 타입을 쓰라고 한 글도 있는데요. 걍 varchar 써두 암 문제 없습니다..
RECENT COMMENT