用正则替换标签内的所有数据

来源:互联网 发布:多益网络笔试题 编辑:程序博客网 时间:2024/06/05 02:59
$str = '<div class="graw">-----------标签内容-----------</div>';
$content = '<ul class="ke-list fix list-paddingleft-2">            <li>                <div class="ke-img">                    <a href="http://www.kgc.cn/uiue" target="_blank" title="移动端UI设计"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<img src="/upload/ad/1449212378483757.jpg" alt="移动端UI设计"/></a>                </div>                <div class="ke-txt">                    <h3>                        移动端UI设计                    </h3>                    <p>                        联合多位UI设计师、UE交互设计师、产品经理大牛倾力打造,通过多个企业真实项目实践及线下翻转课堂,全面讲解和训练目前热门的移动端主流应用App设计、用户体验(UE)与交互设计、Axure产品原型设计、跨平台(iOS/Android )、多终端设计(手机/Pad/智能电视/微信新媒体),带你快速成长为移动互联网时代最抢手的移动端UI设计师、UE交互设计师。                    </p>                </div>            </li>            <li>                <div class="ke-img">                    <a href="http://www.kgc.cn/media" target="_blank" title="新媒体体系课程"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<img src="/upload/ad/1449213144964572.jpg" alt="新媒体体系课程"/></a>                </div>                <div class="ke-txt">                    <h3>                        
                                            [replyview]新媒体体系课程[/replyview]

                    </h3>
                    <p>
                        课工场新媒体学院,是全网唯一提供新媒体体系课程的学院。在这里,你将在直播老师的带领下,学习、互动、完成作业练习,直到掌握真正技能能够胜任企业工作。在这里,你将一网打尽新媒体相关的所有干货:软件、书籍、资料整合贴……全部为你提供,节省你全网搜索的时间。在这里,你可以结识全国的新媒体同行,和他们交流学习,成为朋友。在这里,立即开始你的新媒体学习之路吧!
                    </p>
                </div>
            </li>
            <li>
                <p>
                    [replyview][/replyview]
                </p>
            </li>
        </ul>';



preg_match_all
("|\[replyview](.*)\[\/replyview]|U", $content, $match);foreach($match[1] as $key=>$val){ $pattern[$key] = "/\[replyview(.+?)\/replyview]/"; $replacement[$key] = $str.$match[1][$key];}$text = preg_replace($pattern,$replacement,$content , 1);
0 0
原创粉丝点击