开发者

Php custom function is Truncating Text but i don't want it to

开发者 https://www.devze.com 2023-01-26 21:20 出处:网络
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\

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消