Inserting header() info into ob_start

From: Date: Wed, 15 Nov 2006 00:53:06 +0000
Subject: Inserting header() info into ob_start
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-244636@lists.php.net to get a copy of this message
How can I insert header() info directly into the ob_start stream? I am compressing a css file with php before it is outputted to the browser, The below DOES work, but I have to insert the php header() info DIRECTLY into the css file. Otherwise, mystyle.css is interpreted as text/html instead of text/css. If possible, I would like to keep css and php code separated. Is this possible, or is there an alternate way? many thanks compress-css.php: <?php /* header info is not working anywhere I put it :( */ /* header('content-type:text/css');*/ header("Expires: ".gmdate("D, d M Y H:i:s", (time()+900)) . " GMT"); */ ob_start("compress"); function compress($buffer) { // remove comments
    $buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
// remove tabs, spaces, newlines, etc.
    $buffer = str_replace(array("\r\n", "\r", "\n", "\t", '  ', '    ', '    '), '', $buffer);
    return $buffer;
} ?> mystyle.css: /* css file is run thru compress-css.php before outputed to the browser */ <?php header('content-type:text/css'); header("Expires: ".gmdate("D, d M Y H:i:s", (time()+900)) . " GMT"); ?> #menu {font: normal 1.88em/1em Georgia, Times New Roman, Times, serif; font-variant: all-caps; margin:0 .1em;} ...rest of css goes here .htaccess file: AddHandler application/x-httpd-php .css php_value auto_prepend_file /path/to/compress-css.php

« previous php.general (#244636) next »