replacing variables in output in php

Posted by Thorpe Obazee on Stack Overflow See other posts from Stack Overflow or by Thorpe Obazee
Published on 2010-05-19T23:54:35Z Indexed on 2010/05/20 0:00 UTC
Read the original article Hit count: 172

Filed under:
|

Right now I have this code.

<?php
    error_reporting(E_ALL);

    require_once('content_config.php');

    function callback($buffer)
    {
        // replace all the apples with oranges
        foreach ($config as $key => $value)
        {
            $buffer = str_replace($key, $value, $buffer);
        }
        return $buffer;
    }

    ob_start("callback");
?>
some content
<?php

ob_end_flush();

?>

in the content_config.php file:

$config['SiteName'] = 'MySiteName';
$config['SiteAuthor'] = 'thatGuy';

What I want to do is that I want to replace the placeholders that with the key of the config array with its value.

Right now, it doesn't work :(

© Stack Overflow or respective owner

Related posts about php

Related posts about output