dongzaotiao2863 2016-05-12 12:58
浏览 65

用php制作一个css文件

I have an css compiler written in PHP. This compiler ensures that all the css files will be minified.

Eventually it echo all the css code. But I don't want to echo the code but that he makes or update a existing css file with the css code that he compiled.

But how is this possible with PHP? Here is the compiler that I use.

$cssFiles = array(
   '',
);

$buffer = "";
foreach ($cssFiles as $cssFile) {
    $buffer .= file_get_contents($cssFile);
}

// Remove comments
$buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
// Remove space after colons
$buffer = str_replace(': ', ':', $buffer);
// Remove whitespace
$buffer = str_replace(array("
", "", "
", "\t", '  ', '    ', '    '), '', $buffer);
// Enable GZip encoding.
ob_start("ob_gzhandler");
// Enable caching
header('Cache-Control: public');
// Expire in one day
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 86400) . ' GMT');
// Set the correct MIME type, because Apache won't set it for us
header("Content-type: text/css");
// Write everything out
echo($buffer);
  • 写回答

1条回答 默认 最新

  • dopii22884 2016-05-12 13:09
    关注

    you can write the $buffer var in existing css file

    $a = fopen("my_css_file_written_with_php.css", 'w');
    fwrite($a, $p);
    fclose($a);
    chmod("my_css_file_written_with_php.css", 0644);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?