我想使用gzcompress()函数从文本文件压缩文本,然后使用gzencode()创建新的压缩文件。它工作正常,但是当我从压缩文件中获取文本并使用gzuncompress()函数对其进行解压缩时,它将乌尔都语字符显示为问号????。
我需要了解丢失的代码。
<?php
$dataTxt = file_get_contents('docket.txt');
//compress text with gzcompress
$compressed_data = gzcompress($dataTxt,9);
//create new file and put the compressed data in it
$random_name = date('ymdhisa').rand(100,3002);
$new_file = file_put_contents($random_name.".txt",$compressed_data);
$data = implode("", file($random_name.".txt"));
$gzdata = gzencode($data, 9);
$fp = fopen($random_name.".txt.gz", "w");
fwrite($fp, $gzdata);
//read from compressed file
$read_file = file_get_contents($random_name.".txt.gz");
//decompress file text
$txt = gzdecode($read_file);
echo(gzuncompress($txt));
fclose($fp);
unlink($random_name.".txt");
?>