2016-09-28 1 views
0

사이에 모든 것을 삭제/일치PHP 정규식이 두 단어 내가 #xyzbegin과 #xyzend 사이의 모든 것을 삭제할

#xyzbegin 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/

RewriteCond %{REQUEST_METHOD} !POST 
RewriteCond %{QUERY_STRING} !.*=.* 
RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$ 
RewriteCond %{DOCUMENT_ROOT}/wp-content/xyz-cache/$1/index.html -f 
RewriteRule ^(.*) "/wp-content/xyz-cache/$1/index.html" [L] 

</IfModule> 
#xyzend 

# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 

# END WordPress 

내 정규식은 다음과 같습니다

'/#xyzbegin(.*)#xyzend/m' 

내가 너무이 시도 :

'/^#xyzbegin(.*)#xyzend$/m' 

둘 다 작동하지 않습니다. 도와주세요.

+0

'(? <= # xyzbegin) (. *?) (? = # xyzend)'? – ndn

+0

파일의 다른 모든 내용을 일치시키고 삭제하는 중 –

+0

어떻게 그렇게됩니까? 우리에게 예제 파일을 줄 수 있습니까? – ndn

답변

0

당신은 여러 일치 s 수정이 필요

<?php 
/** 
*/ 

$in = <<<CODE 

#xyzbegin 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/

RewriteCond %{REQUEST_METHOD} !POST 
RewriteCond %{QUERY_STRING} !.*=.* 
RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$ 
RewriteCond %{DOCUMENT_ROOT}/wp-content/xyz-cache/$1/index.html -f 
RewriteRule ^(.*) "/wp-content/xyz-cache/$1/index.html" [L] 

</IfModule> 
#xyzend 

# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 
# END WordPress"; 
CODE; 



echo preg_replace('/#xyzbegin(.*)#xyzend/s','',$in); 
+0

이상한 http://www.noupe.com/development/php-regular-expressions.html에 의하면 m은 여러 줄을 의미하지만 실제로 작동합니다. –

+0

'm' multiline'^ $'을 사용하는 경우's'는 개행 문자를'.'과 매치하는 것입니다. – cske

관련 문제