Search code examples
character-encodingiconv

shell command iconv doesn't give the asked charset


I have a file in charset US-ASCII and want to encode it in UTF-8.

> file -i from.php
from.php: text/x-php; charset=us-ascii

I type this command :

> sudo -u www-data iconv -f US-ASCII -t UTF8 from.php > to.php

The file to.php is created but with the wrong charset.

> file -i to.php
to.php: text/x-php; charset=us-ascii

I checked the iconv list of charset and US-ASCII and UTF8 seem to be well writen.

This command doesn't work any better :

sudo -u www-data iconv -f US-ASCII -t UTF8 -o to.php from.php

Solution

  • I think I found the solution.

    The file stay in us-ascii simply because it doesn't contain any non-ASCII characters like accented letter.

    I added an accented letter in the file and retype the command :

    > file -i to.php
    to.php: text/x-php; charset=utf-8
    

    Yeah !

    Hope it will help someone.