0

I have the a block of HTML code read into a variable $content:

<div class="entry">
    <table class="old-style1 old-style2">
        <tr>
            <td></td>
        </tr>
    </table>
</div>

I would like to remove all classes/attributes of the existing <table> element and replace it with new classes and another <div> wrapper.

to:

<div class="entry">
    <div class="table-wrapper">
        <table class="new-style1 new-style2">
            <tr>
                <td></td>
            </tr>
        </table>
    </table>
</div>

I might have multiple table elements within the <div class="entry"> block. And I would like to apply the same style modification to all of them.

How can I get the done in the PHP level using RegEx or other methods?

KDX
  • 611
  • 2
  • 10
  • 22
  • 1
    Sure duplicate of http://stackoverflow.com/questions/36950368/how-to-dynamically-modify-css-class-using-javascript-jquery-with-wrapper – i-- Apr 30 '16 at 04:40
  • PHP approach is a totally different question than javascript implementation. What I'm trying to achieve might not be possible without RegEx or a proper parser as suggested in the first comment. jQuery does get the job done at run-time in a limited way, but if the browser's javascript was turned off, the layout design will be a mess. I'm seeking for a most efficient and simple solution instead of analyzing all different scenarios w/ multiple if statements. In the first comment, there are lots of useful reading, yet I can't manage to give all of them a try, any comment on which is recommended? – KDX Apr 30 '16 at 15:07

0 Answers0