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

一个字符串偏题

WBOY
WBOYOriginal
2016-06-13 12:52:15701browse

一个字符串难题~

本帖最后由 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 />
?>


最终结果要变成

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


把第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 />


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

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