开发者

php use preg_replace remove div

I tried use preg_replace remove the div which class="image content", I use some code below开发者_运维问答, but still remain two </div> after my preg_replace, need a help, thanks.

<style>
#contract{width:100%;height:100%;}
#content{width:1002px;overflow:hidden;margin:0 auto;}
</style>
<div id="contract">
<div id="content">
<?php
$html = <<<EOT
<div style="float:left;" class="image content"><div style="float:left;"><div style="float:left;">
    <img alt="Se hai problemi nella visualizzazione dei caratteri, clicca qui." src="../../image/1001.jpg" >
</div></div></div>
<div class="content" style="float:left;"><i>some content here.</i></div>
EOT;
echo preg_replace('/<div(.*?)class="image content">([\s\S]*?)<\/div>/','',$html);
?>
</div>
</div>

I need return: <div class="content" style="float:left;"><i>some content here.</i></div>


I know it's not answer to this question, but don't use regular expressions for manipulating with DOM. There are specialized classes for that (DOMDocument), which are faster and will cause you less headache.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜