1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| $css = <<< EOCSS
* {
margin: 0px;
padding: 0px;
}
html {
background-color: #ccc;
}
body {
width: 960px;
margin: auto;
margin-top: 20px;
margin-bottom: 20px;
}
EOCSS;
$js = <<< EOJS
alert('hello !');
EOJS;
function foo () {
global $js, $css;
$js .= 'alert("foo");';
$html = '<h1>FOO</h1>';
return compact('js','css','html');
}
function bar () {
global $js, $css;
$css .= 'h1 { color: red }';
$html = '<h1>BAR</h1>';
return compact('js','css','html');
}
// NOW WE START //
if (isset($_GET['page']) && function_exists($fct = strtolower($_GET['page']))):
extrac( $fct() );
$js = preg_replace('~\s{2,}~', ' ', $js);
$css = preg_replace('~\s{2,}~', ' ', $css);
$page = <<< EOFILE
<html>
<head>
<title>FooBar page</title>
<script type="text/javascript">{$js}</script>
<style type="text/css">{$css}</style>
</head>
<body>
{$html}
</body>
</html>
EOFILE;
echo $page;
else:
header("HTTP/1.0 404 Not Found");
exit();
endif; |