求正则匹配第一行指定字符串,该如何处理

WBOY
Release: 2016-06-13 12:09:52
Original
1008 people have browsed it

求正则匹配第一行指定字符串
只删除第一行以#p#结束的字符串


$body="我们来自五湖四海 我们爱我们的家乡#p#

四川好啊,湖南好啊,广东好啊,重庆好啊


#e#p#

四川好啊,湖南好啊,广东好啊,重庆好啊


"
$body=preg_replace('/........./is', '',$body,1);


输出:

四川好啊,湖南好啊,广东好啊,重庆好啊


四川好啊,湖南好啊,广东好啊,重庆好啊



------解决思路----------------------
$body=preg_replace('/.+?#p#/is', '',$body,1);
------解决思路----------------------
那为什么 #e#p# 也被删除了?
------解决思路----------------------
preg_replace('/(.*)#p#(\r\n)+/i', '',$body);
------解决思路----------------------
楼主我和2楼有同样疑问你说只删除第一行字符串那为什么你在输出的时候那个#e#p#字符没有了。这串字符(#e#p#)要还是不要啊?
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!