Jump to content

Replace HTML 5 Tag Contents


FishSword

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/257304-replace-html-5-tag-contents/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.