Inside a function a variable has it's own scope, so in order to use $format the way you want to you'll need to do one of two things:
1.) make the variable global:
$format = "";
foo();
echo $format;
function foo() {
global $format;
$format = "bar";
}
2.) pass a reference to the variable:
$format = "";
foo($format);
echo $format;
function foo(&$variable) {
$variable = "bar";
}
Both of these approaches will produce the same result, echoing bar.