preg_replace_callback匹配多行和单行html元素

时间:2016-11-21 12:06:42

标签: php regex dom preg-replace-callback

我需要解析HTML并删除任何属性中的换行符。我尝试使用ism开关,但它返回所有字符串而不是元素。

以下是我正在使用的HTML:

<element type="contentlist" name="content1" template="
    <div class='content-item'>
        <img src='{thumb 128 128}' width='128' height='128' default='files/thumb/default.jpg' />
        <div class='title'>{title}<small>{title_description}</small></div>
        <div class='author'>{author}</div>
        <div class='views'>{views}</div>
        <div class='created_date'>{created_date %Y %B %d %A}</div>
        <div class='edited_date'>{edited_date %Y %B %d %A}</div>
        <div class='abstract'>{abstract 120}</div>
        <div class='tags'>{tags}</div>
        <div class='category'>{category}</div>
        <a class='readmore' href='{link}'>{readmore}</a>
    </div>" description="test html" />
<element type="video" name="VIDEO1" description="test html" folder="files/upload" file="vid" autoplay width="1024" loop="false" />
<element type="html" name="html1" description="test html" />
<element type="image" name="image2" hint="" description="" width="800" height="600" file="test2.jpg" folder="files/upload" />
<element type="text" name="text1" description="test text 1" max-length="256" max-words="50" />
<element type="slickslider" name="slider1" description="test text 1" />
<element type="list" name="list1" description="Menu" text-wrapper="span" text-class="text-center" class="xyz" ul-class="ul" li-class="li" />
<element type="gallery" name="gallery1" description="test text 1" />

我用于单行的正则表达式是:

/<element.*\/>/m

0 个答案:

没有答案