<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解析器.