Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: Conversion from UTF-8 to windows-1256 encoding

by iman_saleh (Novice)
on Oct 29, 2007 at 11:25 UTC ( [id://647820]=note: print w/replies, xml ) Need Help??


in reply to Re: Conversion from UTF-8 to windows-1256 encoding
in thread Conversion from UTF-8 to windows-1256 encoding

Thanks, I tried your code it works but it displays the following message when I run it: "\x{feff}" does not map to cp1256, <IN> line 1. And the character \x{feff} is displayed at the beginning of the file before the text in the output file, I don't know why?
  • Comment on Re^2: Conversion from UTF-8 to windows-1256 encoding

Replies are listed 'Best First'.
Re^3: Conversion from UTF-8 to windows-1256 encoding
by almut (Canon) on Oct 29, 2007 at 12:21 UTC
    "\x{feff}" does not map to cp1256, <IN> line 1. And the character \x{feff} is displayed at the beginning of the file

    FEFF is the unicode character code of the BOM (Byte Order Mark). You just have to ignore it (i.e skip over or remove it from the input).

    (With UTF-8, the BOM has no real use (the byte order is always the same), but on Windows the BOM is generally used to identify the file as being unicode encoded.)

Re^3: Conversion from UTF-8 to windows-1256 encoding
by Sixtease (Friar) on Oct 29, 2007 at 11:50 UTC

    I guess your input file contains non-utf8 characters then. I think I was in a similar situation when I was mailed some utf8-encoded text documents and for some reason I don't know, there was a non-utf8 char at the very beginning. I guess the easiest way to go is to call getc(IN) just before the loop. This would assume though that there indeed is an invalid character there - adding some tests on the return value of getc may be necessary if you're not sure.

    ...I could also be totally wrong and your input file is OK and the problem is somewhere else.

    update:

    FEFF is the unicode character code of the BOM (Byte Order Mark).
    I said wrongly that there is a non-UTF8 character (meaning non-utf8 byte sequence) and I was wrong. Of course, according to the error message, the unicode character only has no equivalent in cp-1256. Thanks almut for a proper explanation.

      Thanks ^_^ now it works fine. It is very strange, I can't find anything wrong with the text, but your suggestion seems to be correct however.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://647820]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-19 13:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found