I apologize for such rudimemtary questions, but I am returning to PHP after a nearly five years away.
I have some html files with embedded php variables in them. Here are some stripped down samples of the actual code, as it is right now.
App.php
<?php
class App
{
public static function Initialize()
{
$sid = session_id();
if (empty($sid))
{
session_start();
}
ob_start('ob_tidyhandler');
Skin::Header('test title');
}
public static function Process()
{
Skin::Error('one is lonely number');
}
public static function Terminate()
{
Skin::Footer();
ob_end_flush();
}
}
?>
Skin.php
<?php
class Skin
{
public static function Render($file, $data)
{
extract($data);
$html = file_get_contents(sprintf('skin/%s.html', $file));
eval("\\$html = \\"$html\\";");
echo($html);
}
public static function Header($title)
{
Skin::Render(
'header',
array(
'title' => $title
)
);
}
public static function Footer()
{
Skin::Render(
'footer',
array()
);
}
public static function Error($message)
{
Skin::Render(
'error',
array(
'message' => $message
)
);
}
}
?>
error.html
<div id="error">
<p>{$message}</p>
</div>
The php error I get is:
Parse error: syntax error, unexpected ‘<’ in /home/drew/public_html/FlashCards/StandAlone/core/Skin.php(13) : eval()'d code on line 2 Parse error: syntax error, unexpected T_STRING in /home/drew/public_html/FlashCards/StandAlone/core/Skin.php(13) : eval()'d code on line 1
Now, don’t bother asking why the functions are all static, there’s a reason, and YES, I know eval is frowned upon, but I can’t see any other way to do this. If there is a better way, please let me know. Otherwise, why doesn’t the above work?
And how the heck do you get indents to work when posting???