php正则替换有关问题,怎么替换成这种形式

WBOY
Release: 2016-06-13 11:49:18
Original
841 people have browsed it

php正则替换问题,如何替换成这种形式?

<br /><div class="item"><br />        <div class="image"><a href="/4_4366/"><img src="/image/4/4366/4366s.jpg" alt="惊悚乐园"  width="120"    style="max-width:90%" /></a></div><br />        <dl><br />           <dt><span>三天两觉</span><a href="/4_4366/">惊悚乐园</a></dt><br />           <dd>    欢迎来到惊悚乐园。<br />    这不仅是游戏,也是挑战和试炼。<br />    恐惧是人类的本能,它使人软弱,惊慌,从而犯下错误。<br />    金钱可以将游戏者武装起来,但智慧和勇气是买不到的。<br />  ...</dd><br />        </dl><br />        <div class="clear"></div><br />      </div><br />
Copy after login

<br /><div class="item"><br />        <div class="image"><a href="/4_4366/"><img src="/image/4/4366/4366s.jpg" alt="惊悚乐园"  width="120"    style="max-width:90%" /></a></div><br />        <dl><br />           <dt><span>三天两觉</span><a href="/4_4366/">惊悚乐园</a></dt><br />           <dd>欢迎来到惊悚乐园。这不仅是游戏,也是挑战和试炼。恐惧是人类的本能,它使人软弱,惊慌,从而犯下错误。金钱可以将游戏者武装起来,但智慧和勇气是买不到的。...</dd><br />        </dl><br />        <div class="clear"></div><br />      </div><br />
Copy after login

过滤掉文字之间的回车和空格,而不是html之间的空格和回车。
------解决方案--------------------
<?php<br />$str =<<<EOD<br /><div class="item"><br />        <div class="image"   ><a href="/4_4366/"><img src="/image/4/4366/4366s.jpg" alt="惊悚乐园"  width="120"    style="max-width:90%" /></a></div><br />        <dl><br />           <dt><span>三<br /><br />           天    <br /><br />              两觉</span><a href="/4_4366/">惊悚乐园</a></dt><br />           <dd>        欢迎来<br /><br />           到惊悚乐园。<br />    这不仅是游戏,也是挑战和试炼。<br />    恐惧是人类的本能,它使人软弱,   <br /><br /><br />    惊慌,从而犯下错误。xx  zzzz<br /><br /><br />xxx<br /><br /><br />    金钱可以将游戏  者武<br /><br /><br /><br />    装起来,但智慧和勇气是买不到的。<br />  ...</dd><br />        </dl><br /><br /><br /><br /><br />        <div class="clear"></div><br />      </div><br />EOD;<br /><br /><br />function shanchu($str){<br /><br />$str = preg_replace('/\s/', '', $str);<br />$str = preg_replace('/\n/', '', $str);<br /><br />return '>'.$str.'<';<br />}<br /><br /><br /><br />echo "<textarea rows=50 cols=100>";<br /><br />print_r(preg_replace("/\>(.+?)\</esi","shanchu('\\1')",$str));<br />echo "</textarea>";<br />echo "
Copy after login
";
exit;

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template