Home  >  Article  >  Backend Development  >  一个字符串难题~

一个字符串难题~

WBOY
WBOYOriginal
2016-06-23 14:02:06825browse

1
2
3
4
";echo $a;?>


最终结果要变成

$a="
1
2
4
";


把第3个去掉~~~

怎么做的?


回复讨论(解决方案)

应该是用js做的或者你利用php的字符串函数也能

可用正则平衡组做

explode
str_replace
preg_replace


说得好像很轻松呀

说得好像很轻松呀
str_replace就可以吧   写个函数传个参数进去,你上面例子就传3 然后前找出之前的内容  一些替换为空
再去掉最后一个 >之前的内容

$a="
1
2
3
4
";$aa=preg_replace("/((
[^<]+){2})(
[^<]+((
[^<]+<\/fieldset>)*)<\/fieldset>)((<\/fieldset>){2})/isU", "\\1\\4\\6", $a);echo $aa;


是不是这样
{}里的数字可以改,想这里写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