The CSS Stylesheet File
PHP code in it. What is more interesting is the benefits of that association as,
purely from a coding point of view, there’s no complexity at all.
visuals.inc
file, the first steps are making surethat any variables passed on to the
stylesheet.css.php
are properlyretrieved. This is where we’ll encounter one of the first benefits of including
PHP code in stylesheet: implement browser based behaviors without having to
create multiple stylesheets. This will be discussed with more details in the
next sections.
visuals.inc
file, this file must be included in the PHP enabledstylesheet. This is done using the
require()
function, as withoutthis file, the stylesheet would not behave properly. Now can start the real fun
of putting some PHP in CSS (I assume you know the basics about CSS). I won’t
explain anything here; see the next sections to understand the why.
<?php
if (substr(phpversion(),0,3) != '4.1') {
$_REQUEST = array_merge($HTTP_POST_VARS, $HTTP_GET_VARS);
}
if ( isset($_REQUEST['browser']) ) {
$browser = $_REQUEST['browser'];
} else if ( !isset($browser) ) {
$browser = 'ie5'; // 94% of the browsers on the web
}
require_once('visuals.inc');
?>
body, h1, h2, h3, h4, h5, h6, p {
font-family: <?php print($VISUALS[$SkinID]['page']['font']); ?>;
font-size: <?php
print($VISUALS[$SkinID]['page']['fontsize']);
print($VISUALS[$SkinID]['page']['fontunit']);
?>;
}
body {<?php
print('background-color: '.$VISUALS[$SkinID]['page']['background']['color'].';');
?>}
<?php
for ($i=1; $i<6; $i++) {
print( 'H'.$i.' { ');
print('font-size: '.($VISUALS[$SkinID]['page']['fontsize']+(6-$i)));
print ($VISUALS[$SkinID]['page']['fontunit'].';');
print('font-weight: bold;');
print (' }');
}
?>