0
votes

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

3
Are there any non-ASCII characters in the file where the encoding would actually make a difference?deceze♦

3 Answers

4
votes

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
1
votes

ASCII, UTF-8 and ISO-8859 are 100% identical encodings for the lowest 128 characters. If your file only contains characters in that range (which is basically the set of characters you find on a common US English keyboard), there's no difference between these encodings.

My guess what's happening: A plain text file has no associated encoding meta data. You cannot know the encoding of a plain text file just by looking at it. What the file utility is doing is simply giving its best guess, and since there's no difference it prefers to tell you the file is UTF-8 encoded, which technically it may well be.

0
votes

In addition to jackjr300 with the following One-Liner you can do it for all php files in the current folder:

for filename in *.php; do  iconv -f ISO_8859-1 -t UTF-8 $filename > temp_$filename && mv -f ./temp_$filename ./$filename; done