Is there a way to test if a string is gzdeflated?
gzinflate()
returns the original string if it's not a gzdeflate()
encoded string.
The most obvious check would be:
$deflated = @gzinflate($data); // to avoid getting a warning
if ($data != $deflated && $deflated !== FALSE) {
$source = gzinflate($data);
}
I don't think there's another way to do this.
I'm agree with @Vlad Preda answer, but we can convert warning to exception:
set_error_handler(function ($code, $description) {
throw new \RuntimeException($description, $code);
});
$deflated = gzinflate($data);
restore_error_handler();
and it provides for us ability to handle exception... and don't suppress warnings...