我得到一个奇怪的错误信息与下面的一些
PHP代码(我不是
PHP专家):
if ( $file_loc != NULL ) { if ( file_exists($file_loc) ) { printf(" file exists"); $handle = fopen($file_loc,"rb"); $contents = fread($handle,filesize($file_loc)); fclose($handle); $result = gzdecode($contents); } }
我基本上是试图从一个gzip压缩的文件加载文本内容.我收到以下错误:
Fatal error: Call to undefined function gzdecode() in ...\sites\MyScripts\fw2.PHP on line 80
然而,当我看看documentation时,似乎不需要加入额外的图书馆,还是我错了?如何解决这个问题?
UPDATE
接下来另一个question来检查这个库是否安装在我的电脑上,答案是肯定的.
从PHP信息:
所以这越来越混乱了…
更新二
我努力了:
<?PHP echo PHPversion().","; if (function_exists("gzdecode")) { echo "gzdecode OK,"; } else { echo "gzdecode no OK,"; } if (extension_loaded('zlib')) { echo "zlib extension loaded "; } else { echo "zlib extension not loaded "; } ?>
我得到:
5.2.17,gzdecode no OK,zlib extension loaded
它并不总是安装.从
the documentation:
原文链接:https://www.f2er.com/php/139858.htmlZlib support in PHP is not enabled by default. You will need to configure PHP –with-zlib[=DIR]
The Windows version of PHP has built-in support for this extension. You do not need to load any additional extensions in order to use these functions.
编辑:由于这是接受的答案仍然,我编辑它添加建议作为替换的功能.
function gzdecode($data) { return gzinflate(substr($data,10,-8)); }