Can someone please explain why this code:
$str = "StackOverflow";
echo $str . " - ";
$strCompressed = gzcompress($str);
//echo $strCompressed . " - ";
$strUncompressed = gzuncompress($strCompressed);
echo $strUncompressed . " - ";
gives the expected output of: StackOverflow - StackOverflow -
but this code (writing and reading from file):
$str = "StackOverflow";
$strCompressed = gzcompress($str);
$file = "test.cache";
$fp = fopen($file, "w");
fwrite($fp, $strCompressed);
fclose($fp);
$strCompressed = readfile($file);
echo gzuncompress($strCompressed);
does not produce the wated output of StackOverflow?
Also, I’m wondering, if I uncoment the commented line of code in the first example (//echo $strCompressed . " - ";) the script will output something like this: StackOverflow - xś.ILÎö/K-JËÉ/, so as you can see without the second StackOverflow - as with that line comented out. Any insight is appreciated.
Try this:
readfiledoesn’t return the file’s contents but outputs them