Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iconv(): Wrong charset, conversion from GBK' to UTF-8//IGNORE' is not allowed in /app/vendor/aliyuncs/oss-sdk-php/src/OSS/OssClient.php on line 2301 #97

Closed
solody opened this issue Jul 30, 2018 · 8 comments

Comments

@solody
Copy link

solody commented Jul 30, 2018

bash-4.3# php -v
PHP 7.1.9 (cli) (built: Oct  2 2017 20:51:54) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.1.9, Copyright (c) 1999-2017, by Zend Technologies
    with Xdebug v2.5.3, Copyright (c) 2002-2017, by Derick Rethans
bash-4.3# php -m
[PHP Modules]
apcu
bcmath
bz2
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gd
gettext
hash
iconv
intl
json
ldap
libxml
mbstring
mcrypt
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
readline
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
sqlite3
standard
sysvmsg
sysvsem
sysvshm
tokenizer
wddx
xdebug
xml
xmlreader
xmlrpc
xmlwriter
xsl
Zend OPcache
zip
zlib

[Zend Modules]
Xdebug
Zend OPcache
@solody
Copy link
Author

solody commented Jul 30, 2018

是Bug吗?还是我环境有问题?

@solody
Copy link
Author

solody commented Jul 30, 2018

@solody
Copy link
Author

solody commented Jul 30, 2018

The "//ignore" option doesn't work with recent versions of the iconv library. So if you're having trouble with that option, you aren't alone.

That means you can't currently use this function to filter invalid characters. Instead it silently fails and returns an empty string (or you'll get a notice but only if you have E_NOTICE enabled).

This has been a known bug with a known solution for at least since 2009 years but no one seems to be willing to fix it (PHP must pass the -c option to iconv). It's still broken as of the latest release 5.4.3.

https://bugs.php.net/bug.php?id=48147
https://bugs.php.net/bug.php?id=52211
https://bugs.php.net/bug.php?id=61484

[UPDATE 15-JUN-2012]
Here's a workaround...

ini_set('mbstring.substitute_character', "none");
$text= mb_convert_encoding($text, 'UTF-8', 'UTF-8');

That will strip invalid characters from UTF-8 strings (so that you can insert it into a database, etc.). Instead of "none" you can also use the value 32 if you want it to insert spaces in place of the invalid characters.

@solody
Copy link
Author

solody commented Jul 31, 2018

docker-library/php#240 如果使用了alpine系统,libiconv的版本会很低,需要更新一下 libiconv的版本

在dockerfile中添加如下命令更新

RUN apk add --no-cache --repository http://dl-3.alpinelinux.org/alpine/edge/testing gnu-libiconv
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php

@inhere
Copy link

inhere commented Dec 5, 2019

现在应该是这样:

# testing -> community
RUN apk add --no-cache --repository http://mirrors.aliyun.com/alpine/edge/community gnu-libiconv
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php

@tekintian
Copy link

just remove the //IGNORE,

$options[self::OSS_OBJECT] = iconv('GBK', "UTF-8", $options[self::OSS_OBJECT]);

@haoshehao
Copy link

docker-library/php#240 如果使用了alpine系统,libiconv的版本会很低,需要更新一下 libiconv的版本

在dockerfile中添加如下命令更新

RUN apk add --no-cache --repository http://dl-3.alpinelinux.org/alpine/edge/testing gnu-libiconv
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php

docker for windows 中怎么打开dockerfile文件呢?

@huiguangjun
Copy link
Contributor

16b47c6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants