0

I need to parse HTML and remove newlines inside of any attributes. I've tried to use the ism switch but it returns all of my strings instead of elements.

Here is the HTML I am working with:

<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" />

And the regex that I used and worked for single line is:

/<element.*\/>/m
Addison
  • 7,322
  • 2
  • 39
  • 55
  • 1
    [Regex is not the correct tool for parsing HTML](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags) [**instead use DOMDocument**](http://stackoverflow.com/questions/3577641/how-do-you-parse-and-process-html-xml-in-php) – Narendrasingh Sisodia Nov 21 '16 at 12:08
  • @NarendrasinghSisodia DOMDocument cant parse multiline html attributes, so i decided to cast multiline attributes to single line before pass to DOMDocument. – Mohammad Reza Hashemi Nov 21 '16 at 12:12
  • DOMDocument **can** parse multiline html attributes – Toto Nov 21 '16 at 15:40

0 Answers0