PHP & Others

preg_match 멀티라인 정규표현식 예제

페이지 정보

본문

m (PCRE_MULTILINE)

s (PCRE_DOTALL)

x (PCRE_EXTENDED)

e (PREG_REPLACE_EVAL)

U (PCRE_UNGREEDY)

 

 

$lineFirst "This is a new first line<br>\r\n";
$lineLast  "This is a new last line<br>\r\n"
;
$page 
= <<<EOD
<html><head>
<title>This is a test page</title>
</head><body>
This is the first line<br>
Hi Fred<br>
Hi Bill<br>
This is the last line<br>
</body>
</html>
EOD;
$re "/<body>.*^(.+)(^.*?^)(.+)(^<\\/body>.*?)/smU"
;
if (
preg_match($re$page$aMatchPREG_OFFSET_CAPTURE
))
$newPage substr($text0$aMatch[1][1
]) .
           
$lineFirst $aMatch[2][0
] .
           
$lineLast $aMatch[4][0
];
print 
$newPage;


http://php.net/manual/en/reference.pcre.pattern.modifiers.php

 

 

관련자료

등록된 댓글이 없습니다.
Today's proverb
우리의 꿈은, 뒤에 오는 사람들이 우리를 딛고 우리 위에서 이루게 하는 것입니다. 나는 평생을 창조적인 작업을 위해서 살아왔습니다. 누가 하라고 해서 한 것이 아니라 그것이 나의 삶 그 자체의 즐거움이었기 때문입니다. 현실을 직시하며 현재의 수준을 유지하라. 그리고 더 먼 곳을 향하는 시야를 가져라.