...or just read the manual on the functionality of [man]fpassthru/man
Th eproblem is that you are using [man]fpassthru/man to pass thru the value to the browser (since this function just reads to the end of the supplied file pointer and dumps the output to the browser. The return value is likely to be how much data was outputted, i.e. 11 bytes - which is the number you are passing back from the function and then echoing out on the screen.
Additonally, [man]fpassthru/man closes the file pointer for you, so there is no need to perform this action.
So - a cleaned up version would be: -
function getFile($filename)
{
if (!$filename) {
return 0;
}
$filename = "tmpl/" . $filename . ".tmpl";
$fp = fopen($filename,r);
if (!$fp) {
return 0;
}
fpassthru($fp);
}
getFile("welcome");
Alternatively - if you want to return the value instead, then try using something like: -
function getFile($filename)
{
if (!$filename) {
return 0;
}
$filename = "tmpl/" . $filename . ".tmpl";
if (!file_exists($filename)) {
return 0;
}
return(implode ('', file ($filename)));
}
echo getFile("welcome");
(I haven't checked the above code, but the general idea should be ok)