Search code examples
macosunixencodingiconv

iconv in Mac OS X 10.7.3 does nothing


I am trying to convert a php file (client.php) from utf-8 to iso-8859-1 and the following command does nothing on the file:

iconv -f UTF-8 -t ISO-8859-1 client.php

Upon execution the original file contents are displayed.

In fact, when I check for the file's encoding after executing iconv with:

file -I client.php

The same old utf-8 is shown:

client.php: text/x-php; charset=utf-8


Solution

  • The iconv utility shall convert the encoding of characters in file from one codeset to another and write the results to standard output.

    Here's a solution : Write stdout to a temporary file and rename the temporary file

    iconv -f UTF-8 -t ISO_8859-1 client.php > client_temp.php && mv -f client_temp.php client.php