src/Crossjoin/Css/Helper/Placeholder.php
public static function replaceStringsAndComments($text)
    {
        if (is_string($text)) {
            // Fast pre-check, to optimize performance
            if (strpos($text, "'") !== false || strpos($text, '"') !== false) {
                // Replace all strings in quotes (also in comments, but that's okay - removed in next step)
                $replaceStringCallback = function ($matches) {
                    return self::addStringReplacement($matches[1] . $matches[2] . $matches[1]);
                };
                $text = preg_replace('/\r/', '', $text);
                $text = preg_replace('/\\\\\n/', '_STRING_CSSLINEBREAK_', $text);
                $text = preg_replace('/\\\\"/', '_STRING_ESCAPEDDOUBLEQUOTE_', $text);
                $text = preg_replace('/\\\\\'/', '_STRING_ESCAPEDSINGLEQUOTE_', $text);
                $text = preg_replace_callback('/("|\')(.*?)\g{1}/', $replaceStringCallback, $text);
            }

            if (strpos($text, "data:") !== false) {
                // Replace all data URIs
                // (that are not in quotes and therefor were not replaced by the previous check)
                $replaceDataUriCallback = function ($matches) {
                    return self::addStringReplacement($matches[1]);
                };
                $text = preg_replace_callback(
                    '/(data:(?:[^;,]+)?(?:;charset=[^;,]+)?' .
                    '(?:;base64,(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?|,[-.a-zA-Z0-9_%]+))/',
                    $replaceDataUriCallback,
                    $text
                );
            }

            // Fast pre-check, to optimize performance
            if (strpos($text, "*") !== false) {
                // Strip multi-line comments (after string replace to keep comments in strings)
                $replaceCommentCallback = function ($matches) {
                    return self::addCommentReplacement($matches[1]);
                };
                $text = preg_replace_callback('/(\/\*.*?\*\/)/', $replaceCommentCallback, $text);
            }

            return $text;
        } else {
            throw new \InvalidArgumentException(
                "Invalid type '" . gettype($text). "' for argument 'text' given."
            );
        }
    }
public static function replaceStringsAndComments($text)
    {
        if (is_string($text)) {
            // Fast pre-check, to optimize performance
            if (strpos($text, "'") !== false || strpos($text, '"') !== false) {
                // Replace all strings in quotes (also in comments, but that's okay - removed in next step)
                $replaceStringCallback = function ($matches) {
                    return self::addStringReplacement($matches[1] . $matches[2] . $matches[1]);
                };
                $text = preg_replace('/\r/', '', $text);
                $text = preg_replace('/\\\\\n/', '_STRING_CSSLINEBREAK_', $text);
                $text = preg_replace('/\\\\"/', '_STRING_ESCAPEDDOUBLEQUOTE_', $text);
                $text = preg_replace('/\\\\\'/', '_STRING_ESCAPEDSINGLEQUOTE_', $text);
                $text = preg_replace_callback('/("|\')(.*?)\g{1}/', $replaceStringCallback, $text);
            }

            if (strpos($text, "data:") !== false) {
                // Replace all data URIs
                // (that are not in quotes and therefor were not replaced by the previous check)
                $replaceDataUriCallback = function ($matches) {
                    return self::addStringReplacement($matches[1]);
                };
                $text = preg_replace_callback(
                    '/(data:(?:[^;,]+)?(?:;charset=[^;,]+)?' .
                    '(?:;base64,(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?|,[-.a-zA-Z0-9_%]+))/',
                    $replaceDataUriCallback,
                    $text
                );
            }

            // Fast pre-check, to optimize performance
            if (strpos($text, "*") !== false) {
                // Strip multi-line comments (after string replace to keep comments in strings)
                $replaceCommentCallback = function ($matches) {
                    return self::addCommentReplacement($matches[1]);
                };
                $text = preg_replace_callback('/(\/\*.*?\*\/)/', $replaceCommentCallback, $text);
            }

            return $text;
        } else {
            throw new \InvalidArgumentException(
                "Invalid type '" . gettype($text). "' for argument 'text' given."
            );
        }
    }
public static function replaceStringsAndComments ( $ text ) { if ( is_string ( $ text ) ) { // Fast pre-check, to optimize performance if ( strpos ( $ text , "'" ) !== false || strpos ( $ text , '"' ) !== false ) { // Replace all strings in quotes (also in comments, but that's okay - removed in next step) $ replaceStringCallback = function ( $ matches ) { return self :: addStringReplacement ( $ matches [ 1 ] . $ matches [ 2 ] . $ matches [ 1 ] ) ; } ; $ text = preg_replace ( '/\r/' , '' , $ text ) ; $ text = preg_replace ( '/\\\\\n/' , '_STRING_CSSLINEBREAK_' , $ text ) ; $ text = preg_replace ( '/\\\\"/' , '_STRING_ESCAPEDDOUBLEQUOTE_' , $ text ) ; $ text = preg_replace ( '/\\\\\'/' , '_STRING_ESCAPEDSINGLEQUOTE_' , $ text ) ; $ text = preg_replace_callback ( '/("|\')(.*?)\g{1}/' , $ replaceStringCallback , $ text ) ; } if ( strpos ( $ text , "data:" ) !== false ) { // Replace all data URIs // (that are not in quotes and therefor were not replaced by the previous check) $ replaceDataUriCallback = function ( $ matches ) { return self :: addStringReplacement ( $ matches [ 1 ] ) ; } ; $ text = preg_replace_callback ( '/(data:(?:[^;,]+)?(?:;charset=[^;,]+)?' . '(?:;base64,(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?|,[-.a-zA-Z0-9_%]+))/' , $ replaceDataUriCallback , $ text ) ; } // Fast pre-check, to optimize performance if ( strpos ( $ text , "*" ) !== false ) { // Strip multi-line comments (after string replace to keep comments in strings) $ replaceCommentCallback = function ( $ matches ) { return self :: addCommentReplacement ( $ matches [ 1 ] ) ; } ; $ text = preg_replace_callback ( '/(\/\*.*?\*\/)/' , $ replaceCommentCallback , $ text ) ; } return $ text ; } else { throw new \ InvalidArgumentException ( "Invalid type '" . gettype ( $ text ) . "' for argument 'text' given." ) ; } }
Replaces all CSS strings and comments in the given text.

@param string $text
@return string
Replaces all CSS strings and comments in the given text .