Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

=?ISO-8859-1 in mail subject

I'm acquiring the unread mails I have in my GMail account through PHP and its method imap_open

When I get the subjects through the method imap_fetch_overview I get some subjects like this:

=?ISO-8859-1?Q?Informaci=F3n_Apartamento_a_la_Venta?= =?ISO-8859-1?Q?_en_Benasque(Demandas:_0442_______)?=

It's unreadable, I think because of its character encoding.

What should I do to make it readable?

like image 729
David Morales Avatar asked Aug 12 '10 14:08

David Morales


People also ask

What is encoding ISO 8859?

ISO/IEC 8859-1 encodes what it refers to as "Latin alphabet no. 1", consisting of 191 characters from the Latin script. This character-encoding scheme is used throughout the Americas, Western Europe, Oceania, and much of Africa.

What is the difference between UTF-8 and ISO 8859-1?

UTF-8 is a multibyte encoding that can represent any Unicode character. ISO 8859-1 is a single-byte encoding that can represent the first 256 Unicode characters. Both encode ASCII exactly the same way.


1 Answers

To get the string in UTF-8, do:

$or = '=?ISO-8859-1?Q?Informaci=F3n_Apartamento_a_la_Venta?= =?ISO-8859-1?Q?_en_Benasque(Demandas:_0442_______)?=';
mb_internal_encoding('UTF-8');
$v = str_replace("_"," ", mb_decode_mimeheader($or));

which gives:

Información Apartamento a la Venta en Benasque(Demandas: 0442       )

You can then convert to ISO-8859-1, if you wish.

like image 127
Artefacto Avatar answered Nov 12 '22 15:11

Artefacto