Replace string from PHP include file

include, php

Solution

You can use this:

<?php

function callback($buffer)
{
  return (str_replace("foo", "cool", $buffer));
}
ob_start("callback");
include 'foo.php';
ob_end_flush();

?> 

Problem

Let's say I have an include file, foo.php, and it contains the text "this file is foo". So, when I load the include using `<?php include 'foo.php'; ?>`, I want to be able to replace a string from the include before displaying the text it contains. So let's say I want to replace "foo" from the include with "cool". Make sense?

Original source