Jump to content


I can't figure this out...


3 replies to this topic

#1 zetsumei

    Young Padawan

  • Publishing Betazoids
  • Pip
  • 269 posts
  • Gender:Male
  • Location:127.0.0.1

Posted 24 January 2007 - 04:29 PM

I can't figure this out for a template engine. I think it's enclosed properly but I'm getting an error

Parse error: syntax error, unexpected $end in /home/vxlabs/public_html/test/template.engine.php(56) : eval()'d code on line 11

heres my template.engine.php code

<?php
class TemplateEngine // This is our TemplateEngine class.
{
	var $Template; // Current Templates Name.
	var $TemplateExt = '.tpl'; // Templates File ext.
	var $TemplateDir = './templates/'; // Templates Dir.
	
	function SelectTemplateFile($file, $error_line = 0, $error_file = '') // This function will select the requested templates .tpl file.
	{
		if(is_dir($this->TemplateDir)) // If the $templatedir exsits.
		{
			if(!file_exists($this->TemplateDir.$file.$this->TemplateExt)) // If the .tpl file does not exsit.
			{
				$error = "<b>File:</b> ".$error_file."<br/>
				<b>Line:</b> ".$error_line."<br/>
				<b>Date:</b> ".date("D M j G:i Y")."<br/><br/>
				Error loading ".$this->TemplateDir.$file.$this->TemplateExt.", file does not exist.";
				return die($error); // Returns $error.";
			}
			elseif(file_exists($this->TemplateDir.$file.$this->TemplateExt)) // ElseIf the file exsits.
			{
				return $this->Template=file_get_contents($this->TemplateDir.$file.$this->TemplateExt); // Returns the current templates data.
			} // End ElseIf.
		}
		elseif(!is_dir($this->TemplateDir)) // ElseIf the directory does not exsit.
		{
				$error = "<b>File:</b> ".$error_file."<br/>
				<b>Line:</b> ".$error_line."<br/>
				<b>Date:</b> ".date("D M j G:i Y")."<br/><br/>
				Error opening ".$this->TemplateDir.", directory does not exist.";
				return die($error); // Returns $error.
		} // End ElseIf.
	} // End Function.
	
	function ReplaceVars($vars=array(), $error_line = 0, $error_file = '') // This will replace {var} with a array value.
	{
		if (sizeof($vars) > 0) // If the array of vars is not emtpy.
		{
			foreach ($vars as $var => $content) // Loops through the array.
			{
				$this->Template=str_replace("{".$var."}", $content, $this->Template); // Replaces {var} with the array value ($content).
			} // End Foreach.
		}
		else // Else the array of vars is empty.
		{
			$error = "<b>File:</b> ".$error_file."<br/>
			<b>Line:</b> ".$error_line."<br/>
			<b>Date:</b> ".date("D M j G:i Y")."<br/><br/>
			Error no tags destined for replacemnt.";
			return die($error); // Returns $error.
		} // End Else.
	} // End Function.
	
	function Compile() // This function will compile to template and display it.
	{
		eval("?>".$this->Template."<?php"); // This simply allows us to add php into the .tpl file it self, and also returns the finished template.
	} // End Function.
} // End Class
?>


#2 bay

    Young Padawan

  • Members
  • Pip
  • 105 posts
  • Gender:Male
  • Location:Chicago, IL USA

Posted 25 January 2007 - 06:50 PM

http://us2.php.net/eval

The user comments will help :D

#3 Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,971 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 26 January 2007 - 04:54 PM

What are you trying to evaluate?

#4 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 26 January 2007 - 06:20 PM

He's trying to evaluate the .tpl data :)
eval("?>".$this->Template."<?php"); // This simply allows us to add php into the .tpl file it self, and also returns the finished template.
But what we need is the code being evaluated... that's why i still prefer includes as opposed to eval(), better error reporting (and same functionality).





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users