I am passing a large amount of text to a PHP function and having it return it compressed. The text is being cut off. Not all of it is being passed back out. Like some of the words at the very end aren't showing up after being compressed. Does PHP limit this somewhere?
function compress($buffer) {
/* remove comments */
$buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
/* remo开发者_StackOverflowve tabs, spaces, newlines, etc. */
$buffer = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $buffer);
return $buffer;
}
Is the function. Its from http://www.antedes.com/blog/webdevelopment/three-ways-to-compress-css-files-using-php
Is there like a setting in php.ini to fix this?
Your compress()
function looks decent for CSS files, not JS. This is what I use to "compress" CSS (including jquery-ui and other monsters):
function compress_css($string)
{
$string = preg_replace('~/\*[^*]*\*+([^/][^*]*\*+)*/~', '', $string);
$string = preg_replace('~\s+~', ' ', $string);
$string = preg_replace('~ *+([{}+>:;,]) *~', '$1', trim($string));
$string = str_replace(';}', '}', $string);
$string = preg_replace('~[^{}]++\{\}~', '', $string);
return $string;
}
and for JavaScript files this one: https://github.com/mishoo/UglifyJS2 (or this: http://lisperator.net/uglifyjs/#demo)
I'm sure there are other good tools for the same tasks, just find what suits you and use that.
精彩评论