lib/Minify/Lines.php
public static function minify($content, $options = array())
    {
        $id = (isset($options['id']) && $options['id']) ? $options['id'] : '';
        $content = str_replace("\r\n", "\n", $content);

        $lines = explode("\n", $content);
        $numLines = count($lines);
        // determine left padding
        $padTo = strlen((string) $numLines); // e.g. 103 lines = 3 digits
        $inComment = false;
        $i = 0;
        $newLines = array();

        while (null !== ($line = array_shift($lines))) {
            if (('' !== $id) && (0 === $i % 50)) {
                if ($inComment) {
                    array_push($newLines, '', "/* {$id} *|", '');
                } else {
                    array_push($newLines, '', "/* {$id} */", '');
                }
            }

            ++$i;
            $newLines[] = self::_addNote($line, $i, $inComment, $padTo);
            $inComment = self::_eolInComment($line, $inComment);
        }

        $content = implode("\n", $newLines) . "\n";

        // check for desired URI rewriting
        if (isset($options['currentDir'])) {
            Minify_CSS_UriRewriter::$debugText = '';
            $docRoot = isset($options['docRoot']) ? $options['docRoot'] : $_SERVER['DOCUMENT_ROOT'];
            $symlinks = isset($options['symlinks']) ? $options['symlinks'] : array();

            $content = Minify_CSS_UriRewriter::rewrite($content, $options['currentDir'], $docRoot, $symlinks);

            $content = "/* Minify_CSS_UriRewriter::\$debugText\n\n"
                 . Minify_CSS_UriRewriter::$debugText . "*/\n"
                 . $content;
        }

        return $content;
    }
public static function minify($content, $options = array())
    {
        $id = (isset($options['id']) && $options['id']) ? $options['id'] : '';
        $content = str_replace("\r\n", "\n", $content);

        $lines = explode("\n", $content);
        $numLines = count($lines);
        // determine left padding
        $padTo = strlen((string) $numLines); // e.g. 103 lines = 3 digits
        $inComment = false;
        $i = 0;
        $newLines = array();

        while (null !== ($line = array_shift($lines))) {
            if (('' !== $id) && (0 === $i % 50)) {
                if ($inComment) {
                    array_push($newLines, '', "/* {$id} *|", '');
                } else {
                    array_push($newLines, '', "/* {$id} */", '');
                }
            }

            ++$i;
            $newLines[] = self::_addNote($line, $i, $inComment, $padTo);
            $inComment = self::_eolInComment($line, $inComment);
        }

        $content = implode("\n", $newLines) . "\n";

        // check for desired URI rewriting
        if (isset($options['currentDir'])) {
            Minify_CSS_UriRewriter::$debugText = '';
            $docRoot = isset($options['docRoot']) ? $options['docRoot'] : $_SERVER['DOCUMENT_ROOT'];
            $symlinks = isset($options['symlinks']) ? $options['symlinks'] : array();

            $content = Minify_CSS_UriRewriter::rewrite($content, $options['currentDir'], $docRoot, $symlinks);

            $content = "/* Minify_CSS_UriRewriter::\$debugText\n\n"
                 . Minify_CSS_UriRewriter::$debugText . "*/\n"
                 . $content;
        }

        return $content;
    }
public static function minify ( $ content , $ options = array ( ) ) { $ id = ( isset ( $ options [ 'id' ] ) && $ options [ 'id' ] ) ? $ options [ 'id' ] : '' ; $ content = str_replace ( "\r\n" , "\n" , $ content ) ; $ lines = explode ( "\n" , $ content ) ; $ numLines = count ( $ lines ) ; // determine left padding $ padTo = strlen ( ( string ) $ numLines ) ; // e.g. 103 lines = 3 digits $ inComment = false ; $ i = 0 ; $ newLines = array ( ) ; while ( null !== ( $ line = array_shift ( $ lines ) ) ) { if ( ( '' !== $ id ) && ( 0 === $ i % 50 ) ) { if ( $ inComment ) { array_push ( $ newLines , '' , "/* {$id} *|" , '' ) ; } else { array_push ( $ newLines , '' , "/* {$id} */" , '' ) ; } } ++ $ i ; $ newLines [ ] = self :: _addNote ( $ line , $ i , $ inComment , $ padTo ) ; $ inComment = self :: _eolInComment ( $ line , $ inComment ) ; } $ content = implode ( "\n" , $ newLines ) . "\n" ; // check for desired URI rewriting if ( isset ( $ options [ 'currentDir' ] ) ) { Minify_CSS_UriRewriter :: $ debugText = '' ; $ docRoot = isset ( $ options [ 'docRoot' ] ) ? $ options [ 'docRoot' ] : $ _SERVER [ 'DOCUMENT_ROOT' ] ; $ symlinks = isset ( $ options [ 'symlinks' ] ) ? $ options [ 'symlinks' ] : array ( ) ; $ content = Minify_CSS_UriRewriter :: rewrite ( $ content , $ options [ 'currentDir' ] , $ docRoot , $ symlinks ) ; $ content = "/* Minify_CSS_UriRewriter::\$debugText\n\n" . Minify_CSS_UriRewriter :: $ debugText . "*/\n" . $ content ; } return $ content ; }
Add line numbers in C-style comments

This uses a very basic parser easily fooled by comment tokens inside
strings or regexes, but, otherwise, generally clean code will not be
mangled. URI rewriting can also be performed.

@param string $content

@param array $options available options:

'id': (optional) string to identify file. E.g. file name/path

'currentDir': (default null) if given, this is assumed to be the
directory of the current CSS file. Using this, minify will rewrite
all relative URIs in import/url declarations to correctly point to
the desired files, and prepend a comment with debugging information about
this process.

@return string
Add line numbers in C - style comments