티스토리 뷰

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, $aMatch, PREG_OFFSET_CAPTURE
))
$newPage = substr($text, 0, $aMatch[1][1
]) .
          
$lineFirst . $aMatch[2][0
] .
          
$lineLast . $aMatch[4][0
];
print
$newPage;

 

 

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

댓글
D-DAY
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/03   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함