Skip to content

Commit 5165533

Browse files
committed
work around an iconv bug in older PHP versions
1 parent aae0916 commit 5165533

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/Zip.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,9 +653,16 @@ protected function cpToUtf8($string)
653653
*/
654654
protected function utf8ToCp($string)
655655
{
656+
// try iconv first
656657
if (function_exists('iconv')) {
657-
return iconv('UTF-8', 'CP437//IGNORE', $string);
658-
} elseif (function_exists('mb_convert_encoding')) {
658+
$string = @iconv('UTF-8', 'CP437//IGNORE', $string);
659+
}
660+
if($string) return $string; // it worked
661+
662+
// still here? iconv failed to convert the string. Try another method
663+
// see http://php.net/manual/en/function.iconv.php#108643
664+
665+
if (function_exists('mb_convert_encoding')) {
659666
return mb_convert_encoding($string, 'CP850', 'UTF-8');
660667
} else {
661668
return $string;

0 commit comments

Comments
 (0)