FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » utf8_encode(utf8_decode(string)) doesn't return same string
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
utf8_encode(utf8_decode(string)) doesn't return same string [message #180480] Thu, 21 February 2013 13:44 Go to next message
Giacomo M is currently offline  Giacomo M
Messages: 15
Registered: February 2013
Karma: 0
Junior Member
Hi everybody,
You know why the code in the subject

utf8_encode(utf8_decode(string))

does not return the same string??

Thanks in advance.

--
Giacomo
Re: utf8_encode(utf8_decode(string)) doesn't return same string [message #180481 is a reply to message #180480] Thu, 21 February 2013 15:18 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
On 21/02/13 13:44, Giacomo M wrote:
> Hi everybody,
> You know why the code in the subject
>
> utf8_encode(utf8_decode(string))
>
> does not return the same string??
>
> Thanks in advance.
>
because something gets 'lost in translation'?

:-)


--
Ineptocracy

(in-ep-toc’-ra-cy) – a system of government where the least capable to
lead are elected by the least capable of producing, and where the
members of society least likely to sustain themselves or succeed, are
rewarded with goods and services paid for by the confiscated wealth of a
diminishing number of producers.
Re: utf8_encode(utf8_decode(string)) doesn't return same string [message #180482 is a reply to message #180481] Thu, 21 February 2013 15:58 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
On 21/02/13 15:18, The Natural Philosopher wrote:
> On 21/02/13 13:44, Giacomo M wrote:
>> Hi everybody,
>> You know why the code in the subject
>>
>> utf8_encode(utf8_decode(string))
>>
>> does not return the same string??
>>
>> Thanks in advance.
>>
> because something gets 'lost in translation'?
>
> :-)
>
>
"Please note that utf8_decode simply converts a string encoded in UTF-8
to ISO-8859-1. A more appropriate name for it would be utf8_to_iso88591.
If your text is already encoded in ISO-8859-1, you do not need this
function. If you don't want to use ISO-8859-1, you do not need this
function.

Note that UTF-8 can represent many more characters than ISO-8859-1.
Trying to convert a UTF-8 string that contains characters that can't be
represented in ISO-8859-1 to ISO-8859-1 will garble your text and/or
cause characters to go missing. Trying to convert text that is not
encoded in UTF-8 using this function will most likely garble the text."

http://www.php.net/manual/en/function.utf8-decode.php


--
Ineptocracy

(in-ep-toc’-ra-cy) – a system of government where the least capable to
lead are elected by the least capable of producing, and where the
members of society least likely to sustain themselves or succeed, are
rewarded with goods and services paid for by the confiscated wealth of a
diminishing number of producers.
Re: utf8_encode(utf8_decode(string)) doesn't return same string [message #180483 is a reply to message #180482] Thu, 21 February 2013 18:39 Go to previous messageGo to next message
Giacomo M is currently offline  Giacomo M
Messages: 15
Registered: February 2013
Karma: 0
Junior Member
Il 21/02/2013 16:58, The Natural Philosopher ha scritto:
> "Please note that utf8_decode simply converts a string encoded in UTF-8
> to ISO-8859-1. A more appropriate name for it would be utf8_to_iso88591.
> If your text is already encoded in ISO-8859-1, you do not need this
> function. If you don't want to use ISO-8859-1, you do not need this
> function.
>
> Note that UTF-8 can represent many more characters than ISO-8859-1.
> Trying to convert a UTF-8 string that contains characters that can't be
> represented in ISO-8859-1 to ISO-8859-1 will garble your text and/or
> cause characters to go missing. Trying to convert text that is not
> encoded in UTF-8 using this function will most likely garble the text."

Not my case. I first encode an ISO string in UTF, after i decode the
same string. Why I get differet strings?

Thanks.

--
Giacomo
Re: utf8_encode(utf8_decode(string)) doesn't return same string [message #180484 is a reply to message #180483] Thu, 21 February 2013 19:08 Go to previous messageGo to next message
Tim Streater is currently offline  Tim Streater
Messages: 328
Registered: September 2010
Karma: 0
Senior Member
In article <kg5plp$jk2$1(at)speranza(dot)aioe(dot)org>,
Giacomo M <kylnas(at)tiscali(dot)it> wrote:

> Il 21/02/2013 16:58, The Natural Philosopher ha scritto:
>> "Please note that utf8_decode simply converts a string encoded in UTF-8
>> to ISO-8859-1. A more appropriate name for it would be utf8_to_iso88591.
>> If your text is already encoded in ISO-8859-1, you do not need this
>> function. If you don't want to use ISO-8859-1, you do not need this
>> function.
>>
>> Note that UTF-8 can represent many more characters than ISO-8859-1.
>> Trying to convert a UTF-8 string that contains characters that can't be
>> represented in ISO-8859-1 to ISO-8859-1 will garble your text and/or
>> cause characters to go missing. Trying to convert text that is not
>> encoded in UTF-8 using this function will most likely garble the text."
>
> Not my case. I first encode an ISO string in UTF, after i decode the
> same string. Why I get differet strings?

Your title doesn't say that. It says you decode first, then encode.

--
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
Re: utf8_encode(utf8_decode(string)) doesn't return same string [message #180485 is a reply to message #180484] Thu, 21 February 2013 19:13 Go to previous messageGo to next message
Giacomo M is currently offline  Giacomo M
Messages: 15
Registered: February 2013
Karma: 0
Junior Member
Il 21/02/2013 20:08, Tim Streater ha scritto:
> In article <kg5plp$jk2$1(at)speranza(dot)aioe(dot)org>,
> Giacomo M <kylnas(at)tiscali(dot)it> wrote:
>
>> Il 21/02/2013 16:58, The Natural Philosopher ha scritto:
>>> "Please note that utf8_decode simply converts a string encoded in UTF-8
>>> to ISO-8859-1. A more appropriate name for it would be
>> utf8_to_iso88591.
>>> If your text is already encoded in ISO-8859-1, you do not need this
>>> function. If you don't want to use ISO-8859-1, you do not need this
>>> function.
>>>
>>> Note that UTF-8 can represent many more characters than ISO-8859-1.
>>> Trying to convert a UTF-8 string that contains characters that can't be
>>> represented in ISO-8859-1 to ISO-8859-1 will garble your text and/or
>>> cause characters to go missing. Trying to convert text that is not
>>> encoded in UTF-8 using this function will most likely garble the text."
>>
>> Not my case. I first encode an ISO string in UTF, after i decode the
>> same string. Why I get differet strings?
>
> Your title doesn't say that. It says you decode first, then encode.

Is it not the same?

I have an ISO-8859-1 xml file that I have to load with simplexml, so I
first decode it. After that, I want to encode to return to ISO-8859-1.
But I get different string.

--
Giacomo
Re: utf8_encode(utf8_decode(string)) doesn't return same string [message #180490 is a reply to message #180485] Thu, 21 February 2013 22:29 Go to previous message
Tim Streater is currently offline  Tim Streater
Messages: 328
Registered: September 2010
Karma: 0
Senior Member
In article <kg5rke$pp4$1(at)speranza(dot)aioe(dot)org>,
Giacomo M <kylnas(at)tiscali(dot)it> wrote:

> Il 21/02/2013 20:08, Tim Streater ha scritto:
>> In article <kg5plp$jk2$1(at)speranza(dot)aioe(dot)org>,
>> Giacomo M <kylnas(at)tiscali(dot)it> wrote:
>>
>>> Il 21/02/2013 16:58, The Natural Philosopher ha scritto:
>>>> "Please note that utf8_decode simply converts a string encoded in UTF-8
>>>> to ISO-8859-1. A more appropriate name for it would be
>>> utf8_to_iso88591.
>>>> If your text is already encoded in ISO-8859-1, you do not need this
>>>> function. If you don't want to use ISO-8859-1, you do not need this
>>>> function.
>>>>
>>>> Note that UTF-8 can represent many more characters than ISO-8859-1.
>>>> Trying to convert a UTF-8 string that contains characters that can't be
>>>> represented in ISO-8859-1 to ISO-8859-1 will garble your text and/or
>>>> cause characters to go missing. Trying to convert text that is not
>>>> encoded in UTF-8 using this function will most likely garble the text."
>>>
>>> Not my case. I first encode an ISO string in UTF, after i decode the
>>> same string. Why I get differet strings?
>>
>> Your title doesn't say that. It says you decode first, then encode.
>
> Is it not the same?
>
> I have an ISO-8859-1 xml file that I have to load with simplexml, so I
> first decode it. After that, I want to encode to return to ISO-8859-1.
> But I get different string.

If you want to do ISO -> UTF8 -> ISO then I would expect to do:

$iso = utf8_decode (utf8_encode ($iso));

according to the documentation, anyway.

--
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: On click button in php
Next Topic: reading from HID keyboard
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Nov 26 23:53:48 GMT 2024

Total time taken to generate the page: 0.02432 seconds