求截取PHP指定字符串代码,该怎么解决

WBOY
Release: 2016-06-13 11:52:41
Original
829 people have browsed it

求截取PHP指定字符串代码
有下面一段html字符串:

aaaa
bbbb
cccc
dddd
 >
要想输出下面内容:
aaaa
dddd
 >
即删除中间两个
前面的内容及
的简易代码,由于还要输出为html,不用数组方式。
------解决方案--------------------
$s = '<td align="Center" rowspan="2" width="7%">aaaa<br>bbbb<br>cccc<br>dddd<br></td >';<br />echo preg_replace('/<br>\w+/', '', $s, 2);
Copy after login
<td align="Center" rowspan="2" width="7%">aaaa<br>dddd<br></td ><br />
Copy after login

------解决方案--------------------
1
echo preg_replace('/<br>[^<]+/', '', $s, 2);
Copy after login


2
echo preg_replace('/\(.+?\)/', '', $s);
Copy after login

------解决方案--------------------
echo preg_replace_callback('/<br>[^<]+/', 'foo', $s, 2); <br />function foo($m){<br />     return strpos($m[0], '(') !== false ? preg_replace('/\(.+?\)/','',$m[0]) : '';	    	 <br />}
Copy after login
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!