Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #11252
| Path | csiph.com!eeepc.pasdenom.info!news.pasdenom.info!news.dougwise.org!aioe.org!feeder.news-service.com!xlned.com!feeder7.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.84.MISMATCH!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Date | Fri, 04 Feb 2011 12:52:01 +0100 |
| From | Luuk <Luuk@invalid.lan> |
| User-Agent | Mozilla/5.0 (Windows; U; Windows NT 6.1; en_US; rv:1.9.2.13) Gecko/20101207 Lightning/1.0b2 Thunderbird/3.1.7 |
| MIME-Version | 1.0 |
| Newsgroups | comp.lang.php |
| Subject | Re: json and non UTF8 |
| References | <iieeug$v8$1@news.albasani.net> <ousq18-kff.ln1@luuk.invalid.lan> <iifhtf$lpk$1@news.albasani.net> <kd2t18-fp3.ln1@luuk.invalid.lan> <iigo1s$ec2$1@news.eternal-september.org> |
| In-Reply-To | <iigo1s$ec2$1@news.eternal-september.org> |
| X-Enigmail-Version | 1.1.1 |
| Content-Type | text/plain; charset=windows-1252 |
| Content-Transfer-Encoding | 8bit |
| Message-ID | <tr5t18-tl4.ln1@luuk.invalid.lan> (permalink) |
| Lines | 65 |
| NNTP-Posting-Host | 80.101.116.74 |
| X-Trace | 1296820318 news.xs4all.nl 34849 [::ffff:80.101.116.74]:35252 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.php:11252 |
Show key headers only | View raw
On 04-02-11 12:31, "Álvaro G. Vicario" wrote:
> El 04/02/2011 11:53, Luuk escribió/wrote:
>> On 04-02-11 01:40, Jeff Thies wrote:
>>> On 2/3/2011 10:07 AM, Luuk wrote:
>>>> On 03-02-11 15:43, Jeff Thies wrote:
>>>>> I've got some text that contains some odd characters that
>>>>> json_encode
>>>>> is returning nulls on. I'd like to either fix the characters, get
>>>>> rid of
>>>>> them or anything that doesn't give me a null.
>>>>>
>>>>> Jeff
>>>>
>>>> Can you give more detail on this 'odd characters'?
>>>> Maybe show them here with bin2hex()?
>>>> i.e. print bin2hex('abcdef');
>>>> 616263646566
>>>
>>> I was trying to json_encode this and it choked on the bullet.
>>>
>>> Project Feasibility& Development
>>> •Client and end user needs assessment
>>>>
>>>> And in the subject you state 'non UTF8'
>>>> In the docs of 'json_encode' i read:
>>>> "This function only works with UTF-8 encoded data"
>>>
>>> Yeah, that is what I noticed too. It took me a couple hours to figure
>>> it out!
>>
>> You could try to convert this text from UTF-8 to another character-set
>>
>> print (json_encode(iconv('UTF-8', \"ISO-8859-15//IGNORE\", '•Client')));
>>
>> this prints "Client";
>
> I admit I'm lost in the thread and I'm not really sure about what the
> problem is but JSON _has_ to be Unicode. It's by design:
>
> «A string is a sequence of zero or more Unicode characters, wrapped in
> double quotes, using backslash escapes.»
>
> http://www.json.org/
>
> And, as already mentioned, json_encode() needs UTF-8 input data:
>
> http://php.net/json_encode
>
> If you need ISO-8859-15 at either end, you need to make a conversion
> from ISO-8859-15 to UTF-8 *before* calling json_encode() and/or a
> conversion from UTF-8 to ISO-8859-15 *after* json_decode().
>
> In any case, every time I hear the expression "odd characters" I suspect
> that the character set of data is simply unknown. The first step is to
> learn which one it is.
>
>
oops..... my mistake! i mixed up the character-sets..
You are right, the text that is used in the json_encode() function must
be encoded in the UTF-8 character-set.
--
Luuk
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: json and non UTF8 Luuk <Luuk@invalid.lan> - 2011-02-03 16:07 +0100
Re: json and non UTF8 Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-02-04 15:25 +0100
Re: json and non UTF8 Jeff Thies <jeff_thies@att.net> - 2011-02-03 19:40 -0500
Re: json and non UTF8 "Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid> - 2011-02-04 12:31 +0100
Re: json and non UTF8 Luuk <Luuk@invalid.lan> - 2011-02-04 12:52 +0100
Re: json and non UTF8 Luuk <Luuk@invalid.lan> - 2011-02-04 11:53 +0100
csiph-web