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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:26:00+00:00 2026-06-11T06:26:00+00:00

I am currently working on a replacement tool that will dynamically replace certain strings

  • 0

I am currently working on a replacement tool that will dynamically replace certain strings (including html) in a website using a smarty outputfilter.

For the replacement to take place, I am using PHP’s str_ireplace method, which reads the code that is supposed to be replaced and the replacement code from a database, and then pass the result to the smarty output (using an output filter), in a similar way as the below.

$tpl_source = str_ireplace($replacements['sourceHTML'], $replacements['replacementHTML'], $tpl_source);  

The problem is, that although it works great on my dev server, once uploaded to the live server replacements occasionally fail. The same replacements work just fine on my dev version though. After some examinations and googling there was not much I could find out regarding this issue. So my question is, what could influence str_replace‘s behavour?

Thanks

Edit with replacement example:

$htmlsource = file_get_contents('somefile.html');
$newstr = str_replace('<a href="http://www.somelink">Some text</a>', 'sometext', $htmlsource);  // the text to be replaced does exist in the html source

fails to replace. After some checking, it looks like the combination of “> creates a problem. But just the combination of it. If I try to change only (“) it works, if I try to change only (>) it works.

  • 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-11T06:26:02+00:00Added an answer on June 11, 2026 at 6:26 am

    This was a trikcy problem, and it ended up having nothing to do with the str_replace method itself;

    We are using smarty as a tamplating system. The str_replace method was used by a smarty ouput filter in order to change the html in some ocassions, just before it was delivered to the user.

    Here is the Smarty outputfilter Code:

    function smarty_outputfilter_replace($tpl_source, &$smarty)
    {
        $replacements = Content::getReplacementsForPage();
        if (is_array($replacements))
        {
            foreach ($replacements as $replacementData)
            {
                $tpl_source = str_replace($replacementData['sourcecode'], $replacementData['replacementcode'], $tpl_source);
            }
        }
        return ($tpl_source);
    }
    

    So this code failed now and then for now apparent reason… until I realized that the HTML code in the smarty template was being manipulated by an Apache filter.

    This resulted into the source code in the browser (which we were using as the code to be replaced by something else) not being identical to the template code (which smarty was trying to modify). Result? str_replace failed 🙂

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

Sidebar

Related Questions

I'm developing a content uploading tool that is currently GETing the html data in
I'm working on a website that will switch to a new style on a
Currently working with converting SQLException error messages into messages that are more useful for
Currently working with NSURLConnection. Found a great website showing important delegate methods coming with
Im currently working on a game that uses multi touch to apply zoom to
Am currently working on an application that requires users to submit posts and comments
Currently working on a game, and is converting it to retina. I am using
Im currently working on a site which will contain a products catalog. I am
Im currently working on a project that requires the following. I need to be
I am currently working on a one-page layout for a website. Each section of

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.