Home > Backend Development > PHP Tutorial > 一个字符串偏题

一个字符串偏题

WBOY
Release: 2016-06-13 12:52:15
Original
706 people have browsed it

一个字符串难题~

本帖最后由 xjl756425616 于 2013-03-06 14:34:05 编辑
<?php<br />
$a="<fieldset>1<fieldset>2<fieldset>3<fieldset>4</fieldset></fieldset></fieldset></fieldset>";<br />
echo $a;<br />
?>
Copy after login


最终结果要变成

$a="<fieldset>1<fieldset>2<fieldset>4</fieldset></fieldset></fieldset>";
Copy after login


把第3个去掉~~~

怎么做的?


------解决方案--------------------
<br />
$a="<fieldset>1<fieldset>2<fieldset>3<fieldset>4</fieldset></fieldset></fieldset></fieldset>";<br />
$aa=preg_replace("/((<fieldset>[^<]+){2})(<fieldset>[^<]+((<fieldset>[^<]+<\/fieldset>)*)<\/fieldset>)((<\/fieldset>){2})/isU", "\\1\\4\\6", $a);<br />
echo $aa;<br />
Copy after login


是不是这样
{}里的数字可以改,想这里写2是因为第三个
前有两个

确实不轻松  楼主给分哈
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