Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8211083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:18:27+00:00 2026-06-07T10:18:27+00:00

Overview: I’m making a tempting system for my sites, which at the moment is

  • 0

Overview: I’m making a tempting system for my sites, which at the moment is going quite well and it is working how I would expect it to, the only problems arise when I would like something like {PAGE_SIDEBAR} to show the file template/sidebar.php or something similar.

I am using

//loads of other str_replace here
$body = str_replace("{PAGE_SIDEBAR}, include("template/sidebar.php"), $body);
echo $body;

this works, however it includes the file at the start of body, NOT where {PAGE_SIDEBAR} is. Where the tag is, it shows the number 1.

See screenshots for better explanation:

How the rendered template looks before

Using the insert code above

Also, for point of interest, How it looks using file_get_contents() instead of include(): http:// http://www.jamesmoorhouse.co.uk/stack_overflow/str_replace/file_get_contents_method.png

Ideally I Am hoping for it to work as it would with the include method, but show up where the file_get_contents method puts it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T10:18:28+00:00Added an answer on June 7, 2026 at 10:18 am

    You have to capture everything that the include spits out using output buffering to be able to use it as a string:

    ob_start();
    include("template/sidebar.php");
    $str_sidebar = ob_get_clean();
    $body = str_replace("{PAGE_SIDEBAR}", $str_sidebar, $body);
    echo $body;
    

    If there are lots of placeholders that you want to replace, you might want to use a regular-expression based solution with a callback so that you don’t have to repeat this code for each. See my answer here for a primer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Overview: I'm working on some windows service using Visual Basic 2010, which deployed on
Overview: I am working on a project which involves a WCF and multiple types
Overview I have an iOS app which sends local notifications at specific dates. I
Overview I have an iOS project which contains 2 navigation controllers as shown in
Overview of the problem In jQuery, the order in which you bind a handler
Overview: I have an Expandable List View which displays items of the type ToDoElement
Situation Overview I'm using Ext.NET GridPanel to display a list of projects which has
Overview This is the scenario: I'm given a value which represents a portion of
Overview I have a iOS project in which the view controller implementation which has
Overview I am working on building a Kynetx ruleset that will find a bunch

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.