我想删除#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 :(得分: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 );