1

你好我有很多div标签,但我想删除那个小div标签中字符的div标签。字符串数<10 ex

$txt=<<<HTML
 <div class="abc"> 123ab</div>
<div id="abc"> 123ab</div>

 <div class="abc"> 123abcdfdfsdfsdfdsfsdfsdfdsf</div>
HTML;

并且只返回 dig(包括长字符串)

$txt=<<<HTML
    <div class="abc"> 123abcdfdfsdfsdfdsfsdfsdfdsf</div>
HTML;
4

1 回答 1

2
preg_replace('#<div(?:[^>]*)>.{0,10}</div>#u','',$txt)

未测试

于 2010-10-07T12:16:53.790 回答