Home > Backend Development > PHP Tutorial > php 正则表达替换,为何不能替换解决思路

php 正则表达替换,为何不能替换解决思路

WBOY
Release: 2016-06-13 13:39:51
Original
1015 people have browsed it

php 正则表达替换,为何不能替换

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
<?php $page = '<!-- WebAppleHeader --><div class="sheader"></div><!-- /WebAppleHeader --> 阿萨德发射点发射得分        <!-- WebAppleIndexBanner -->
            <img  src="/images/sinaapp/img/example1.png" class="sbanner" alt=" php 正则表达替换,为何不能替换解决思路 " >
        <!-- /WebAppleIndexBanner -->';




[b]//替换内容
$local_replace_area[0] = 'replace_area_1<hr>';   //这里替换不了?

$patterns[0] = "/^<!-- WebAppleHeader -->[\s\S]*<!-- \/WebAppleHeader -->$/i";//这里替换不了?[/b]

$page = preg_replace($patterns, $local_replace_area, $page);       

echo $page;
?>


Copy after login






------解决方案--------------------
$patterns[0] = "/^[\s\S]*$/i";//这里替换不了?[/b]

最后的$有问题,并不是字符串结束部分,去掉试试?
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template