'bbd9ee', /* masthead */ 'fgmast' => '4d4d4d', 'bgmenu' => 'e7e4d3', /* menu */ 'fgmenu' => '444', 'bgcont' => 'fff', /* content */ 'fgcont' => '444' ); /* alternate color scheme 1 */ $alternate1 = array( 'bgmast' => 'ddb', 'fgmast' => '000', 'bgmenu' => 'aa7', 'fgmenu' => 'fff', 'bgcont' => 'fff', 'fgcont' => '333' ); /* alternate color scheme 2 */ $alternate2 = array( 'bgmast' => '399', 'fgmast' => 'fff', 'bgmenu' => 'eb5', 'fgmenu' => '000', 'bgcont' => 'eee', 'fgcont' => '000' ); /* decide what to do based on the incoming query string variable "scheme" or lack of one in the case of the persistent stylesheet */ /* note that the switch/case control or conditional construct below is functionally equivalent to an if... else if... else statement I just happen to think it's easier to read, code and understand */ switch ($_GET['scheme']) { case 'alt2': $comment = 'alternate Color Scheme #2 (Author\'s Selections)'; $scheme = $alternate2; break; case 'alt1': $comment = 'alternate Color Scheme #1 (W3C CSS)'; $scheme = $alternate1; break; default: $comment = 'persistent Color Scheme (Digital Web Magazine)'; $scheme = $persistent; /* first return the basic visual rules for the mock-up elements there is no need to do this again for the alternate styles, all that is necessary is to redefine the colors note: this is the so-called heredoc or here document syntax, everything between the print statement below and the line with the _CSS label by itself will be returned to the browser */ /* there are other ways to do this -- my preference */ print <<<_CSS /* css-demo.php */ /* Dynamic CSS in PHP * Digital Web Magazine * author: Douglas Clifton * Feb-14-2005 */ /* wrapper */ #mockup { width: 400px; height: 200px; margin: 1em 0; padding: 0; border: 1px solid #000; } /* masthead */ #mock-mast { width: 100%; height: 40px; line-height: 40px; margin: 0; padding: 0; border-bottom: 1px solid #000; } #mock-mast h1.demo { background-image: none; font-size: 20px; margin: 0 0 0 14px; padding: 0; } /* menu */ #mock-menu { float: left; width: 99px; height: 159px; font-size: small; margin: 0; padding: 0; border-right: 1px solid #000; } #mock-menu h2.demo { text-align: center; margin-top: 10px; font-size: medium; } #mock-menu ol { text-align: center; list-style-type: none; } #mock-menu ol li { font-size: small; text-decoration: underline; margin: 0; } /* content */ #mock-cont { font-size: small; height: 159px; margin: 0 0 0 100px; padding: 0 0 0 10px; border: 0; } #mock-cont h2.demo { margin: 10px 0 0 0; padding: 0; font-size: medium; } #mock-cont p { width: 280px; margin: 10px 0 0 0; padding: 0; font-size: small; } /* end static CSS */ _CSS; } /* end switch() */ /* now send one of the three color sets, depending on how the script was called notice I am "protecting" each color variable (de)reference by surrounding them with braces: { and } otherwise you confuse the PHP parser */ print <<<_CSS /* begin dynamic CSS: the C stands for Cascade */ /* $comment */ #mockup { background-color: #${scheme['bgcont']}; } #mock-mast { background-color: #${scheme['bgmast']}; } #mock-mast h1 { color: #${scheme['fgmast']}; } #mock-menu { background-color: #${scheme['bgmenu']}; } #mock-menu h2 { color: #${scheme['fgmenu']}; } #mock-menu ol { color: #${scheme['fgmenu']}; } #mock-cont h2 { color: #${scheme['fgcont']}; } #mock-cont p { color: #${scheme['fgcont']}; } /* end dynamic CSS */ _CSS; /* css-demo.php end script */ ?>