Skip to content

Instantly share code, notes, and snippets.

@butihuzi
Last active August 29, 2015 14:05
Show Gist options
  • Save butihuzi/a082009ab6b35380e324 to your computer and use it in GitHub Desktop.
Save butihuzi/a082009ab6b35380e324 to your computer and use it in GitHub Desktop.
压缩加密文本为二进制文件
#!/usr/bin/php -q
<?php
$base_dir = dirname(__FILE__);
$file = $base_dir . '/config/database.local.xml';
$output_file = $base_dir . '/../Resources/conf/database.local.xml';
if (file_exists($output_file) && filemtime($file) <= filemtime($output_file)) {
echo "no update for config file\n";
exit();
}
$xml = file_get_contents($file) or exit(1);
$xml = replace_html_comment($xml);
$zipxml = gzcompress($xml, 9);
$prefix = pack("L", 0x12548763);
$re = file_put_contents($output_file, $prefix . $zipxml);
if ($re) {
echo "compress database file OK!\n";
} else {
echo "compress database file fail\n";
exit(1);
}
function replace_html_comment($input)
{
$reg = "/<![ \r\n\t]*(--([^\-]|[\r\n]|-[^\-])*--[ \r\n\t]*)>/";
$output = preg_replace($reg, "", $input);
$output = preg_replace("/^\s*[\r\n]+/m", "", $output);
// echo $output,PHP_EOL;
return $output;
}
//by sir shu 201408
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment