The following is a PHP generated stylesheet that uses a template for a chat room. I'm just posting it as an example which you might be able to adapt to your own purposes. Notice the header that specifies the content type:
header('Content-type: text/css');
//I forgot what v stands for, but it's an array of user defined styles.
$v['uid'] = 'u'.$id;
$v['msg_bg'] = 'FFFFFF';//background color of message window
$v['user_c'] = '0114A0';//color of user's name
$v['action_c'] = '990000';//color of enter/exit messages
$v['other_c'] = '270049';//color of the names of others
$v['text_c'] = '000000';//general text color
$v['font_s'] = '16';
$v[''] = '';
$v[''] = '';
$css = <<<EOTAAA
#userwindow{
margin: 0 0 20px 20px;
}
#messagewindow, #userwindow{
background-color: #%msg_bg%;
font-size: %font_s%px;
font-family: Tahoma, cx-bair, Arial, sans-serif;
}
#messagewindow p {
color: #%text_c%;
font-family: Tahoma, cx-bair, Arial, sans-serif;
}
#messagewindow p b, #userwindow p{
color: #%other_c%;
}
#messagewindow p.self b, p#%uid%{
color: #%user_c%;
}
#messagewindow p span{
color: #%action_c%;
text-transform: uppercase;
font-size: 12px;
}
EOTAAA;
//custom font filenames
$cx[] = "bair";
$cx[] = "century_gb";
$cx[] = "oakwood";
$cx[] = "plantc";
$cx[] = "salzburg-bold";
$cx[] = "sanskrit";
$cx[] = "timess";
$font_css = '';
$font_template = <<<EOTAAB
@font-face {
font-family: cx-%fontname%;
src: url("%url%fonts/%fontname%.eot");
}
@font-face {
font-family: cx-%fontname%;
src: url("%url%fonts/%fontname%.ttf");
}
EOTAAB;
foreach ($cx as $key => $value){
$font_css .= str_replace(array('%fontname%', '%url%'), array($value, base_url()), $font_template);
}
foreach ($v as $key => $value){
$search[] = '%'.$key.'%';
$replace[] = $value;
}
echo str_replace($search, $replace, $css).$font_css;