php – 如何使用preg_replace替换多行上的文本

嗨,在html页面中有以下内容,可以拉伸多行

<div class="c-fc c-bc" id="content">
                <span class="content-heading c-hc">heading 1 </span><br />
                The Home Page must provide a introduction to the services provided.<br />
                <br />
                <span class="c-sc">Sub heading</span><br />
                The Home Page must provide a introduction to the services provided.<br />
                <br />
                <span class="c-sc">Sub heading</span><br /> 
                The Home Page must provide a introduction to the services provided.<br />
            </div>

我需要在< div class =“c-fc c-bc”id =“content”>之间替换everthing.和< / div>自定义文字

我使用以下代码来完成此操作但如果它是多行则不想工作,但如果evertinh在一行中则有效

$body = file_get_contents('../../templates/'.$val['url']);

$body = preg_replace('/<div class=\"c\-fc c\-bc\" id=\"content\">(.*)<\/div>/','<div class="c-fc c-bc" id="content">abc</div>',$body);

我错过了什么吗?

解决方法:

如果这不是HTML,我会告诉你使用DOTALL修饰符来改变它的含义.从’匹配除新线之外的所有内容’到’匹配所有内容’:

preg_replace('/(.*)<\/div>/s','abc',$body);

但这是HTML,所以请改用HTML解析器.

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...