Well, I probably made this way too complicated, but here the solution  
I came up with by googling a bit.

The solution below allows for some variable substitution WITHOUT  
altering the CSS file.
The body's font-size attribute is  dynamically written according to  
the OS as defined in the user agent.
I guess you could have done this with javascript, but I tend to be  
more comfortable with php.

  If you put the htaccess file in the same directory as the css file,  
it appears to work in IE, Firefox, and Safari.
Just make sure the php file is absolutely targeted in the htaccess file.
An example would be:
/home/mydomain.com/www/php/compress_css.php

After hearing about Yahoo's font css from the list, I may use that.
Regardless, variable substitution is a pretty cool concept for  
CSS....at least in theory.



htaccess file:
#Run CSS Files in the Directory Through the PHP engine
#Run the script 'compress_css.php' before you run any css files in  
this Directory
#
AddHandler application/x-httpd-php .css
php_value auto_prepend_file /home/www/path/to/php/compress_css.php



compress_css.php file:
<?php
ob_start ("compress_css");

// Depending on the OS of the user_agent, create a font-size  
attribute for the Body
strstr ($_SERVER['HTTP_USER_AGENT'], "Macintosh") ?
print "body { font-size:76%;}" :  /*UserAgent says its a Mac*/
print "body { font-size:100%;} ";  /*PC*/

// Read the CSS file directly into this function
// Then, add some headers and compress the file
//
function compress_css($buffer) {
header("Content-type: text/css; charset: UTF-8");       
header("Cache-Control: must-revalidate");
$offset = 60 * 60 ;
$ExpStr = "Expires: " .
gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
header($ExpStr);

// remove comments from the css file
  $buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);

// remove tabs, spaces, newlines, etc.
$buffer = str_replace(array("\r\n", "\r", "\n", "\t", '  ', '    ',  
'    '), '', $buffer);

return $buffer; 

   }
?>


______________________________________________________________________
css-discuss [EMAIL PROTECTED]
http://www.css-discuss.org/mailman/listinfo/css-d
IE7 information -- http://css-discuss.incutio.com/?page=IE7
List wiki/FAQ -- http://css-discuss.incutio.com/
Supported by evolt.org -- http://www.evolt.org/help_support_evolt/

Reply via email to