Jump to content

Replace HTML tag


erme

Recommended Posts

Hi,

 

I am including a file with PHP. The file contains basic html.

 

What I want is to be able replace a tag contained in this file with another one when outputted on the page I am including it on.

 

Eg: replace <h3>Title</h3> as in the file with <h1>Title</h1> on the page.

 

I have found this:

 

$str = str_replace(array('<h3>', '</h3>'), array('<h1>', '</h1>', $str);

 

But don't know how I would integrate it with my include:

 

<?php include('file.txt'); ?>

 

Many thanks

 

 

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

You would need to replace:

 

<?php include('file.txt'); ?>

 

With:

 

<?php
ob_start()
include('file.txt');
echo str_replace(array('<h3>', '</h3>'), array('<h1>', '</h1>', ob_get_clean());
?>

 

This puts the contents of the call to include within a buffer that you can then manipulate using whatever functions you like.

Link to comment
https://forums.phpfreaks.com/topic/263985-replace-html-tag/#findComment-1352886
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.