mirror of
https://github.com/Ne-Lexa/php-zip.git
synced 2025-08-04 22:47:24 +02:00
cp866 to utf8 converter
This commit is contained in:
@@ -311,7 +311,7 @@ class ZipInputStream implements ZipInputStreamInterface
|
||||
fread($this->in, 42)
|
||||
);
|
||||
|
||||
// $utf8 = 0 !== ($data['gpbf'] & self::GPBF_UTF8);
|
||||
// $utf8 = ($data['gpbf'] & ZipEntry::GPBF_UTF8) !== 0;
|
||||
|
||||
// See appendix D of PKWARE's ZIP File Format Specification.
|
||||
$name = fread($this->in, $data['fileLength']);
|
||||
|
@@ -28,4 +28,29 @@ class StringUtil
|
||||
return $needle === "" || (($temp = strlen($haystack) - strlen($needle)) >= 0
|
||||
&& strpos($haystack, $needle, $temp) !== false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $str
|
||||
* @return string
|
||||
*/
|
||||
public static function cp866toUtf8($str)
|
||||
{
|
||||
if (function_exists('iconv')) {
|
||||
/** @noinspection PhpComposerExtensionStubsInspection */
|
||||
return iconv('CP866', 'UTF-8//IGNORE', $str);
|
||||
} elseif (function_exists('mb_convert_encoding')) {
|
||||
/** @noinspection PhpComposerExtensionStubsInspection */
|
||||
return mb_convert_encoding($str, 'UTF-8', 'CP866');
|
||||
} elseif (class_exists('UConverter')) {
|
||||
/** @noinspection PhpComposerExtensionStubsInspection */
|
||||
$converter = new \UConverter('UTF-8', 'CP866');
|
||||
return $converter->convert($str, false);
|
||||
} else {
|
||||
static $cp866Utf8Pairs;
|
||||
if (empty($cp866Utf8Pairs)) {
|
||||
$cp866Utf8Pairs = require __DIR__ . '/encodings/cp866-utf8.php';
|
||||
}
|
||||
return strtr($str, $cp866Utf8Pairs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
BIN
src/PhpZip/Util/encodings/cp866-utf8.php
Normal file
BIN
src/PhpZip/Util/encodings/cp866-utf8.php
Normal file
Binary file not shown.
Reference in New Issue
Block a user