Exemple #1
0
 /**
  * 复制目录
  * @param string $olddir 原目录
  * @param string $newdir 目标目录
  * @param bool $strip_space 去空白去注释
  * @return bool
  */
 public static function copy($olddir, $newdir, $strip_space = false)
 {
     $olddir = self::dirPath($olddir);
     $newdir = self::dirPath($newdir);
     if (!is_dir($olddir)) {
         error("复制失败:" . $olddir . "目录不存在");
     }
     if (!is_dir($newdir)) {
         self::create($newdir);
     }
     foreach (glob($olddir . '*') as $v) {
         $to = $newdir . basename($v);
         if (is_file($to)) {
             continue;
         }
         if (is_dir($v)) {
             self::copy($v, $to, $strip_space);
         } else {
             if ($strip_space) {
                 $data = file_get_contents($v);
                 file_put_contents($to, strip_space($data));
             } else {
                 copy($v, $to);
             }
             chmod($to, "0777");
         }
     }
     return true;
 }
function parse_rules($css)
{
    // make these variables available to this function
    global $file_selector;
    global $file_props;
    // get the selectors contained in this part of the sheet
    $selector = substr($css, 0, strpos($css, '{'));
    // get the css properties and values contained in this part of the sheet
    $props = trim(substr($css, strlen($selector) + 1, -1));
    // remove extra space from before, between and after the selector(s)
    strip_space($selector);
    // remove any additional space
    $selector = trim(eregi_replace(', +', ',', $selector));
    $selector = trim(eregi_replace(' +,', ',', $selector));
    // seperate selector(s) and add to the global selector array
    $file_selector[] = array_unique(explode(',', $selector));
    // shorten the css code
    strip_space($props);
    // remove any additional space
    $props = trim(eregi_replace('(:|;) +', '\\1', $props));
    $props = trim(eregi_replace(' +(:|;)', '\\1', $props));
    $props = trim(eregi_replace('\\( +', '(', $props));
    $props = trim(eregi_replace(' +\\)', ')', $props));
    // if the last character is a semi-colon
    if (substr($props, strlen($props) - 1, 1) == ';') {
        // remove it
        $props = substr($props, 0, -1);
    }
    // seperate properties and add to the global props array
    $file_props[] = explode(';', $props);
}
Exemple #3
0
 public function _case($attr, $content, $res)
 {
     $value = $attr['value'];
     $php = '';
     //组合成PHP
     $php .= '<?php ' . " case {$value} :{ ?>";
     $php .= strip_space($content);
     $php .= '<?php }?>';
     return $php;
 }
Exemple #4
0
/**
 * 多个PHP文件合并
 * @param array $filenameArr    文件    
 * @param type $delSpace        是否删除注释及空格
 */
function php_merge($filenameArr, $delSpace = false)
{
    if (!is_array($filenameArr)) {
        $filenameArr = array($filenameArr);
    }
    $str = '';
    //格式化后的内容
    foreach ($filenameArr as $file) {
        $data = trim(file_get_contents($file));
        $data = substr($data, 0, 5) == '<?php' ? substr($data, 5) : $data;
        $data = substr($data, -2) == '?>' ? substr($data, 0, -2) : $data;
        if ($delSpace) {
            $data = strip_space($data);
        }
        $str .= $data;
    }
    return $str;
}