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 8964057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:29:58+00:00 2026-06-15T16:29:58+00:00

Hello friends I am having trouble getting desired results using str_replace (); function of

  • 0

Hello friends I am having trouble getting desired results using str_replace (); function of PHP.

My code is like this:

<?php ob_start (); /* Start Buffering */

$layout = 'climate';

?>

<div>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc pellentesque.</p>

<img src="images/industry/pic1.jpg"/>
<img src="products/images/industry/pic2.jpg"/>
<img src="samples/products/images/industry/pic3.jpg"/>

</div>

<?php ob_get_contents();  /* Get the Buffer */

$content = str_replace('/desktop/', $layout . '/images/', $layout);

echo $content;

ob_end_flush (); /* Send Output to the browser */

?>

Now here what I am trying to do is let the entire page get generated, then I want to get the generated page and replace a specific word in it’s paths. Finally send the buffer to Browser.

Please Note:

I am very new to PHP hence please request you to help me correct this code to correct syntax.

These paths in my output are generated by the CMS I am using hence I have no control on them.

The value to $layout variable is assigned by another PHP function. I did not mention that snippet just to avoid confusion.

Since my theme is Non-JavaScript I do not intend to use any JavaScript.

Desired output:

I want /industry/ to be replaced by the value of /$layout/ in entire page before sending it to the browser.

<div>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc pellentesque.</p>

<img src="images/climate/pic1.jpg"/>
<img src="products/images/climate/pic2.jpg"/>
<img src="samples/products/images/climate/pic3.jpg"/>

</div>

Lastly :

Please feel free to suggest any other solution if you feel is better than this one.

  • 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-15T16:29:59+00:00Added an answer on June 15, 2026 at 4:29 pm

    You can get the buffer and close it with ob_get_clean(), then do your replacement and echo the $content, which will send it to the browser.

    $content = ob_get_clean();  
    $content = str_replace('/industry/', '/' . $layout . '/', $content);
    echo $content;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello friends I am using this code in my view.. Using this code I
Hello friends i am running code given below which contains the setLogTimeEntery function and
Hello friends here's my code function dropItems(idOfDraggedItem,targetId,x,y) { var html = document.getElementById('dropContent').innerHTML; if(html.length<=0){ html.innerHTML='<img
Hello I am having trouble using multiquery in facebook .net. I am trying to
hello friends i am using this galleria gallery link to display images on my
hello friends i am working on a like module .and having some difficulties running
Hello friends i need to get user information from facebook i am using code
Hello I am having trouble with using dynamic arrays within a class. I am
Hello fellow SO friends, I am having trouble with my syntax in adding a
Hello friends i have this class that is getting values from the database: import

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.