Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.