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?

2
  • 1
    Sure duplicate of stackoverflow.com/questions/36950368/… Commented Apr 30, 2016 at 4: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? Commented Apr 30, 2016 at 15:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.