Jump to content

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

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.