Files
typecho/tools/tc.php
joyqi 55379c90df 初始化
修改了上一个版本的一些错误,第一次提交
2013-07-17 13:13:57 +08:00

29 lines
630 B
PHP

<?php
/** 参数不存在则退出 */
if (!isset($argv[1])) {
echo 'no args';
exit(1);
}
/** 解析所有的参数 */
parse_str($argv[1], $options);
/** 必要参数检测 */
if (!isset($options['in']) || !isset($options['out'])) {
echo 'no input or output file';
exit(1);
}
$str = php_strip_whitespace($options['in']);
$str = preg_replace("/require_once\s+('|\")[_0-9a-z-\/\.]+\\1\s*;/is", '', $str);
$str = trim(ltrim($str, '<?php'));
if (file_exists($options['out'])) {
$str = file_get_contents($options['out']) . $str;
} else {
$str = '<?php ' . $str;
}
file_put_contents($options['out'], $str);