Replace HTML 5 Tag Contents

Discussion in 'PHP' started by FishSword, Feb 19, 2012.

  1. #1
    Hello there,

    Using PHP, what's the best way of replacing the contents between different HTML 5 element tags on the fly?
    Some of the elements I'm looking to change can be found below.

    I have looked into the possibility of using Regular Expressions, but have found lots of material on the internet that try to prevent you from using such a method for parsing HTML due to speed and other HTML code related issues.

    Any help, example code, and ideas on this is greatly appreciated.

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="utf-8" />
    <title>Some Title</title>
    </head>
    
    <body>
    <div>Replace contents of div tag.</div>
    <p class="someClass">Replace contents of p tag.</p>
    
    <table>
      <tr>
        <th>Static Table Heading 1</th>
        <th>Static Table Heading 2</th>
        <th>Static Table Heading 3</th>
      </tr>
      <tr>
        <td>Replace Table Data 1 Contents</td>
        <td>Replace Table Data 2 Contents</td>
        <td>Replace Table Data 3 Contents</td>
      </tr>
      <tr>
        <td>Replace Table Data 4 Contents</td>
        <td>Replace Table Data 5 Contents</td>
        <td>Replace Table Data 6 Contents</td>
      </tr>
    </table>
    </body>
    </html>
    Code (markup):
     
    FishSword, Feb 19, 2012 IP
  2. MarPlo

    MarPlo Member

    Messages:
    97
    Likes Received:
    2
    Best Answers:
    2
    Trophy Points:
    48
    #2
    Hi,
    Try to use php dom. Look on the net for: PHP DOM HTML .
     
    MarPlo, Feb 19, 2012 IP