My function is causing Notice: Undefined variable

I have been trying few different approaches trying to get rid of the underfined variable notices with no luck. Below code is what’s causing the notice but i couldn’t seem to locate the problem:

	function DisplayLayout($template, $variables) {  
		$result=implode(file($template), "");  
		eval( "global $variables;");  
		$variables = str_replace(",","",$variables);
		$var_list = explode("\\$",$variables);
		while($i<=sizeof($var_list)) {
				$result = str_replace("<%$var_list[$i]%>",$$var_list[$i],$result);
		print $result;

Notice the line if(isset($var_list[$i])), that took care of the undefined offset notices but not the variables.

I understand that I can turn the error reporting off but I would rather learn how to deal with the issue, if possible.

Any pointer or suggestion as to how to proceed is greatly appreciated.

I would say that this may have something to do with it:

eval( "global $variables;");

You have an extra semi-colon, should be:

eval( "global $variables");

I’m trying to understand your function.

Because… what i’m seeing, can be represented as:

    function DisplayLayout($template, $variables) {  
      $result = file_get_contents($template);
      $replacements = $GLOBALS[$variables];
      foreach($replacements AS $key => $value) {
      return $result;

(I’m assuming $variables holds the name of a globally-defined associative array in the form ‘tobereplaced’ => ‘valuetoreplacewith’. Would be easier just to pass the array in, but w/e.)