PHP 8.4.24 Released!

Voting

: two plus four?
(Example: nine)

The Note You're Voting On

detain at interserver dot net
8 years ago
gzipped strings include header/metadata you can use to determine if a string is gzipped or not , but since gzcompress does not include that I found myself needing a way to determine if a string was compressed or not.      After some research (and then improvements) i came up with this:

/**
 * determines if a string is a gzipped string supporting strings
 * encoded with either gzencode or gzcompress
 *
 * @param string $string the string to check for compression
 * @return bool whether or not the string was compmressed
 */
function is_gzipped($string) {
    return mb_strpos($string, "\x1f\x8b\x08", 'US-ASCII') === 0 && @gzuncompress($string) !== FALSE;
}

<< Back to user notes page

To Top