Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > it.comp.www.php > #21713 > unrolled thread

Problema Charset e mb_detect_encoding

Started byNoS <NoS@nospam.no>
First post2017-09-10 10:06 +0200
Last post2017-09-14 12:51 +0100
Articles 4 — 3 participants

Back to article view | Back to it.comp.www.php


Contents

  Problema Charset e mb_detect_encoding NoS <NoS@nospam.no> - 2017-09-10 10:06 +0200
    Re: Problema Charset e mb_detect_encoding Leonardo Serni <lserni@gmail.com> - 2017-09-13 21:24 +0200
      Re: Problema Charset e mb_detect_encoding NoS <NoS@nospam.no> - 2017-09-14 08:54 +0200
        Re: Problema Charset e mb_detect_encoding Alessandro Pellizzari <shuriken@amiran.it> - 2017-09-14 12:51 +0100

#21713 — Problema Charset e mb_detect_encoding

FromNoS <NoS@nospam.no>
Date2017-09-10 10:06 +0200
SubjectProblema Charset e mb_detect_encoding
Message-ID<op2rqb$1gpu$1@gioia.aioe.org>
Devo elaborare una stringa (non ho controllo a monte, devo prendere la 
stringa e ridarla in HTML-ENTITIES).

Esempio di stringhe problematiche:
1 - Atà Trinità;
2-  Atà Trinit� (il diamond è sempre una "à").


La 1, per avere il giusto output la devo trattare così:

$stringa_1 = mb_convert_encoding($stringa, "HTML-ENTITIES", "UTF-8");

Ma se tratto la 2 allo stesso modo il risultato in uscita è:

- At� Trinit�

Allora avevo pensato di creare un metodo per testare che tipo di 
codifica mi entrava ed ho preprocessato la stringa con:

     $res = mb_detect_encoding ($stringa, "auto");

Il problema è che il risultato per entrambe le stringhe è "UTF-8", 
quindi non so come comportarmi.

Cosa sto sbagliando?

Grazie in anticipo









[toc] | [next] | [standalone]


#21717

FromLeonardo Serni <lserni@gmail.com>
Date2017-09-13 21:24 +0200
Message-ID<lf1jrclne1iv84c6kon8mle2kt40fhtu0j@L.Serni>
In reply to#21713
On Sun, 10 Sep 2017 10:06:37 +0200, NoS <NoS@nospam.no> wrote:

>Allora avevo pensato di creare un metodo per testare che tipo di 
>codifica mi entrava ed ho preprocessato la stringa con:

>     $res = mb_detect_encoding ($stringa, "auto");

>Il problema è che il risultato per entrambe le stringhe è "UTF-8", 
>quindi non so come comportarmi.

>Cosa sto sbagliando?

Tu poco. Ma prova:

    mb_detect_encoding($stringa, 'UTF-8, ISO-8859-1', true);

per sicurezza.

Quello che io temo è che abbia sbagliato chi ti dà la stringa e ti stia
mandando robaccia in mixed charset, che ripulirla è da piangere sangue.

Il tuo esempio 2 mi fa temere questo.

Leonardo
-- 

A terrible beauty is born.
                                     - W. B. Yeats, Easter 1916

[toc] | [prev] | [next] | [standalone]


#21718

FromNoS <NoS@nospam.no>
Date2017-09-14 08:54 +0200
Message-ID<opd92e$be$1@gioia.aioe.org>
In reply to#21717
Grazie per la risposta,
e si è un pasticcio.

Il 13/09/2017 21:24, Leonardo Serni ha scritto:
> mb_detect_encoding($stringa, 'UTF-8, ISO-8859-1', true);

Ad ogni modo, non avevo capito di poterla usare così questa funzione.
Grazie, così facendo identifico i charset (se tipo UTF-8 e ISO-8859-1) e 
li posso trattare ognuno a suo modo, corretto?

[toc] | [prev] | [next] | [standalone]


#21719

FromAlessandro Pellizzari <shuriken@amiran.it>
Date2017-09-14 12:51 +0100
Message-ID<f1v8pdFtq3tU1@mid.individual.net>
In reply to#21718
On 14/09/2017 07:54, NoS wrote:

> Grazie per la risposta,
> e si è un pasticcio.
> 
> Il 13/09/2017 21:24, Leonardo Serni ha scritto:
>> mb_detect_encoding($stringa, 'UTF-8, ISO-8859-1', true);
> 
> Ad ogni modo, non avevo capito di poterla usare così questa funzione.
> Grazie, così facendo identifico i charset (se tipo UTF-8 e ISO-8859-1) e 
> li posso trattare ognuno a suo modo, corretto?

Il secondo parametro è la lista dei charset da provare, in ordine. Il 
primo che sembra somigliare a un risultato decente viene preso.

Ho perso una settimana a fare esperimenti, e ti posso dire per 
esperienza che quella funzione non funziona (pun intended).

Non che altri metodi (anche con altri linguaggi e tool) funzionino 
meglio, eh!

O sai esattamente il charset originale o non c'è modo di dargli una 
lista che funzioni sempre. E se sai il charset non hai necessità di 
farne il detect.

Bye.

[toc] | [prev] | [standalone]


Back to top | Article view | it.comp.www.php


csiph-web