Home  >  Article  >  Backend Development  >  正则表达式如何将带有标识的元素里的内容批量替换?

正则表达式如何将带有标识的元素里的内容批量替换?

WBOY
WBOYOriginal
2016-06-23 14:27:151079browse



        
  • 11111111111

  •         
  • 22222222222

  •         
  • 33333333333

  •     





    
11111111111

        
22222222222

    




  • 11111111111

  • 22222222222

  • 33333333333




11111111111
22222222222
33333333333




正则表达式,如何将带有 class="label" 标识的元素里的内容批量替换?

回复讨论(解决方案)

你没有说明修改成什么,就假定删除吧!

$s =<<< TXT<div class="label"><dl>    	<dt>11111111111</dt>        <dd>22222222222</dd>    </dl></div><ul class="label"><li>11111111111</li><li>22222222222</li><li>33333333333</li></ul><p class="label"><a href="#">11111111111</a><a href="#">22222222222</a><a href="#">33333333333</a></p>TXT;echo preg_replace('#(<(\w+).+?class="label"\s*>).+?(</\2>)#s', '$1$3', $s);
<div class="label"></div><ul class="label"></ul><p class="label"></p>

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