函数从其他文件返回字符串

I want to make a really simple template engine for my site, to make it easier to add new pages and edit other ones.

I have a template.php file and a variable of $pageHeader. Then in my functions.php file I have a function called CallHeader() with this code:

function CallHeader()
{
        echo $pageHeader;
}

The problem is this does not echo the contents of $pageHeader to the page. I have included template.php in functions.php using:

include("template.php");

I have also tried setting $pageHeader to be global but nothing works. I'm trying to call this from index.php, which has functions.php included. If I set the CallHeader() function like this:

function CallHeader()
{
        echo "test";
}

It works, and echo's "test" to the page on index.php

Any help as to why I can't echo the contents of $pageHeader? Thanks

you tried this and it didn't work ?

function CallHeader()
{
    global $pageHeader;
    echo $pageHeader;
}
function CallHeader()
{
        echo $GLOBALS['pageHeader'];
}

global variables are a liability, not an asset. you've been warned, don't come back whining that you've shot your foot.