php define variable inside str_replace array

Posted by john on Stack Overflow See other posts from Stack Overflow or by john
Published on 2010-03-18T21:49:19Z Indexed on 2010/03/18 21:51 UTC
Read the original article Hit count: 123

Filed under:
|
|

I have a template system, that replaces text such as {HEADER} with the appropriate content. I use an array like this, that replaces the key with the value using str_replace.

$array = array("HEADER","This is the header");
    foreach($array as $var => $content) {
       $template = str_replace("{" . strtoupper($var). "}", $content,$template);
    }

Now im trying to use a defined variable like this:

define("NAME","Site Name");

Inside the value for the header. So I want the defined variable to be inside the array which gets replaced so it would look like this, but it doesn't work.

$array = array("HEADER","Welcome to ".NAME."'s website!");

Any ideas? tell me if im not clear

© Stack Overflow or respective owner

Related posts about php

Related posts about template