Use gzinflate() when you need to decompresses a raw DEFLATE string in a PHP application. The examples below show the actual operation and its limitations.
What Is gzinflate() in PHP?
Decompresses a raw DEFLATE string. The exact signature supported by your installation depends on its PHP version and enabled extensions.
Its syntax is:
gzinflate(string $data, int $max_length = ...): string|false
Parameters and return value: The parameter types, optional arguments, references, and return type are shown in the signature above. Optional parameters are marked with an ellipsis in this reference signature.
Example 1: Basic Usage
<?php
echo gzinflate(gzdeflate("Hello"));
Output:
Hello
Example 2: Different Input or Behavior
<?php
echo gzinflate(gzdeflate("Report"));
Output:
Report
Practical Example: Applying the Function
<?php
$original = "Archive data"; $compressed = gzdeflate($original); $restored = gzinflate($compressed); echo $restored === $original ? "Restored" : "Mismatch";
Output:
Restored
Important Behavior and Edge Cases
Do not feed arbitrary untrusted compressed blobs without decompression-size limits.
Comparison With Related Functions
| Approach | Difference |
|---|---|
gzinflate() | Decompresses a raw DEFLATE string. |
| Related operation | gzuncompress() expects zlib-wrapped data, not raw DEFLATE. |
Common Beginner Mistakes
| Mistake | Correct Approach |
|---|---|
| Ignoring the function-specific limitation | Do not feed arbitrary untrusted compressed blobs without decompression-size limits. |
| Confusing this function with a related operation | gzuncompress() expects zlib-wrapped data, not raw DEFLATE. |
Key Takeaways
- Decompresses a raw DEFLATE string.
- Do not feed arbitrary untrusted compressed blobs without decompression-size limits.
- gzuncompress() expects zlib-wrapped data, not raw DEFLATE.
Use gzinflate() for the specific operation demonstrated above. Check its prerequisites and handle failure conditions before using it with production data.