PHP提供了:
一,gzcompress() 和gzuncompress() 函数
$str = 'Art is contemplation. It is the pleasure of the mind which searches into nature and which there divines the spirit of which nature herself is animated.
Auguste Rodin
Art is contemplation. It is the pleasure of the mind which searches into nature and which there divines the spirit of which nature herself is animated.
Auguste Rodin
Art is contemplation. It is the pleasure of the mind which searches into nature and which there divines the spirit of which nature herself is animated.
Auguste Rodin
Art is contemplation. It is the pleasure of the mind which searches into nature and which there divines the spirit of which nature herself is animated.
Auguste Rodin ';
$stred = gzcompress($str);
echo strlen($str).'<br>'; //684
echo strlen($stred).'<br>'; //133
$unstred = gzuncompress($stred);
echo strlen($stred).'<br>'; //133
echo strlen($unstred).'<br>'; //684
二,gzencode() 和 gzdecode() 函数来压缩
$str = 'Art is contemplation. It is the pleasure of the mind which searches into nature and which there divines the spirit of which nature herself is animated.
Auguste Rodin
Art is contemplation. It is the pleasure of the mind which searches into nature and which there divines the spirit of which nature herself is animated.
Auguste Rodin
Art is contemplation. It is the pleasure of the mind which searches into nature and which there divines the spirit of which nature herself is animated.
Auguste Rodin
Art is contemplation. It is the pleasure of the mind which searches into nature and which there divines the spirit of which nature herself is animated.
Auguste Rodin ';
$stred = gzencode($str);
echo strlen($str).'<br>'; //684
echo strlen($stred).'<br>'; //145
$unstred = gzdecode($stred);
echo strlen($stred).'<br>'; //145
echo strlen($unstred).'<br>'; //684
几乎有50%以上的压缩比率~
gzcompress() 和gzuncompress() //好
比
gzencode() 和 gzdecode() //较好