php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44096 iconv: wrong charset
Submitted: 2008-02-11 08:40 UTC Modified: 2008-02-25 01:31 UTC
Votes:58
Avg. Score:4.3 ± 0.9
Reproduced:50 of 52 (96.2%)
Same Version:7 (14.0%)
Same OS:12 (24.0%)
From: cpuidle at gmx dot de Assigned:
Status: No Feedback Package: ICONV related
PHP Version: 5.2.5 OS: WinXP
Private report: No CVE-ID: None
 [2008-02-11 08:40 UTC] cpuidle at gmx dot de
Description:
------------
Trying simple charset conversion with iconv:

iconv('iso-8859-1', 'utf-8', 'test');

receive this error:

Notice: iconv() [function.iconv]: Wrong charset, conversion from `ISO8859-1' to `UTF-8' is not allowed in /var/htdocs/test.php on line 5

Problem: no troubleshooting information available, e.g. list or supported charsets or similiar. 

How can this be diagnosed?

Reproduce code:
---------------
error_reporting(E_ALL);
$res = iconv('iso-8859-1', 'utf-8', 'test');

Expected result:
----------------
No error and/or supporting functions to aid diagnostics.

Actual result:
--------------
Error message:

Notice: iconv() [function.iconv]: Wrong charset, conversion from `ISO8859-1' to `UTF-8' is not allowed in /var/htdocs/test.php on line 5


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-02-13 17:52 UTC] jani@php.net
In what charset is the input here..?
 [2008-02-13 19:01 UTC] cpuidle at gmx dot de
See test case- file is ansi, not even any complex characters?
 [2008-02-14 22:45 UTC] jani@php.net
Another reason for this is that those encodings just don't exist on your platform. The code works fine for me on Linux..
 [2008-02-22 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2008-02-24 23:45 UTC] darop68 at poczta dot onet dot pl
I have the same problem in php 5.2.5.
My code:
iconv('iso-8859-2', 'utf-8', 'test');
 [2008-02-25 01:31 UTC] rasmus@php.net
Weird Windows-specific thing.  The test case works fine on 6 different UNIX variants I just tried it on.
 [2008-04-17 08:41 UTC] i dot pavlov at korekom dot net
The same thing here. But the problem is far from Windows-specific.
Debian based system in my case.
No usefull info found for now.
 [2008-05-13 05:11 UTC] iconv dot 20 dot cheef-daniel at spamgourmet dot com
Notice: iconv() [function.iconv]: Wrong charset, conversion from `ISO-8859-1' to `UTF-8//TRANSLIT' is not allowed in /var/www/test.php on line 7

Same here with libapache2-mod-php5.2.6 on my debian etch based system. I first thought it has to do with my chroot-setup and spent 2 days searching what goes wrong and found nothing. It works fine with an old php4-binary, iconv directly called in the shell works too.

samples from ANSI encoded file:
echo iconv('UTF-8', 'ASCII//TRANSLIT', "test"); // works
echo iconv('ASCII', 'UTF-8//TRANSLIT', "test"); // works

echo iconv('UTF-8', 'ISO-8859-1//TRANSLIT', "test"); // works not
echo iconv('ISO-8859-1', 'UTF-8//TRANSLIT', "test"); // works not
 [2009-02-12 06:40 UTC] niloat at gmail dot com
Please check whether necessary so files exists in /usr/lib/gconv.
You can copy those files from other's linux system if missing someone.
 [2009-02-26 06:25 UTC] aboh24 at gmx dot de
Same problem on Solaris 10 and explicit compiled and  linked libiconv-1.12 and php 5.2.8. with --with-iconv-dir=<path to libiconv-1.12 lib>

PHP Notice:  iconv(): Wrong charset, conversion from `UTF-8' to `ASCII//TRANSLIT' is not allowed in /sisis/home/sisis/suchopac/query.php on line 39
PHP Notice:  iconv(): Wrong charset, conversion from `ASCII' to `UTF-8//TRANSLIT' is not allowed in /sisis/home/sisis/suchopac/query.php on line 40
PHP Notice:  iconv(): Wrong charset, conversion from `UTF-8' to `ISO-8859-1//TRANSLIT' is not allowed in /sisis/home/sisis/suchopac/query.php on line 42
PHP Notice:  iconv(): Wrong charset, conversion from `ISO-8859-1' to `UTF-8//TRANSLIT' is not allowed in /sisis/home/sisis/suchopac/query.php on line 43
 [2009-03-10 12:58 UTC] cancausecancerr at yahoo dot com dot cn
I got the error while querying a lucene index I just created from a mysql utf8 table (populated with danish data). When I created the index I used 'utf8' while adding fields so everything should be fine. I don't get the error when I query my other tables which have english data and were created in exactly the same manner.

Notice: iconv() [function.iconv]: Wrong charset, conversion from `utf8' to `ASCII//TRANSLIT' is not allowed in Z:\Zend\Search\Lucene\Analysis\Analyzer\Common\Text.php on line 57

Windows NT 5.1 build 2600
Apache/2.2.4
MySQL 5.1.22-rc-community
PHP Version 5.2.6

PHPINFO ICONV:
iconv support 	enabled
iconv implementation 	"libiconv"
iconv library version 	1.11

Directive	Local Value	Master Value
iconv.input_encoding	ISO-8859-1	ISO-8859-1
iconv.internal_encoding	ISO-8859-1	ISO-8859-1
iconv.output_encoding	ISO-8859-1	ISO-8859-1
 [2009-03-10 13:31 UTC] cancausecancerr at yahoo dot com dot cn
I found my problem. It was 'utf8' vs. 'utf-8'. 

I peeked inside Zend Lucene Lucene's code and saw it was looking for 'utf8' or 'utf-8' so I thought I'd save a byte and take 'utf8' (shakes fist at Zend then at self:: for being cheap). 

I echo'd out what Zend Lucene was populating the iconv() with and that's where I saw my prob.

As for the reason my english data wasn't raising this error, I indexed those tables with 'utf-8'.

So it seems my error was the same as everyone elses (encoding type didn't exist on my systema)
 [2010-06-07 23:22 UTC] icovt at yahoo dot com
mod_php iconv() is not working properly if your apache is chrooted and you do not 
have the content of /usr/lib/gconv/ folder into your relative chroot path (i.e. 
/your/chroot/path/usr/lib/gconv/). 
You can simply do: 
cp /usr/lib/gconv/* /your/chroot/path/usr/lib/gconv/
... and re-try.

This was a fix for me, hope this could save time for somebody else.

P.S. Btw, initially iconv() called from command line (using php cli) was OK.
 [2014-07-15 21:19 UTC] aj07mm at hotmail dot com
Same prob here

Notice: iconv(): Wrong charset, conversion from `utf8' to `ascii//TRANSLIT' is not allowed

my charset:

  'input_encoding' => string 'ISO-8859-1' (length=10)
  'output_encoding' => string 'ISO-8859-1' (length=10)
  'internal_encoding' => string 'ISO-8859-1' (length=10)
 [2015-12-28 10:19 UTC] michal at cihar dot com
We've seen this several times on phpMyAdmin, see
https://github.com/phpmyadmin/phpmyadmin/issues/11787/

In most cases this has happened on Windows or Mac, though there are few errors from Linux servers as well. Happens with many PHP versions (at least 5.3, 5.4, 5.5, 5.6 and 7.0).
 [2021-09-11 11:22 UTC] jesus dot inica at gmail dot com
Fixed by installing `php7-mbstring` `php7-iconv` in that order

```bash
RUN apk --no-cache add php7-mbstring php7-iconv
```

Original solution here: https://github.com/docker-library/php/issues/240#issuecomment-355489551
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 01 20:01:29 2024 UTC