Advanced PHP help needed!

Soldato
Joined
12 Jan 2004
Posts
6,824
Location
Londinium
Hey peeps,

writing my own PHP webmail client but Im having a problem with multipart message subjects. I can get most of the subject fine, but sometimes there are weird characters that don't get decoded properly, and i don't know how to decode them into plain text. For example:

Code:
=?UTF-8?Q?Halifax_Promotion_=E2=80=93_Be_prepar?= =?UTF-8?Q?ed_for_the_end_of_the_tax_year?=

I can decode to:

Code:
Halifax Promotion – Be prepared for the end of the tax year

by using imap_mime_header_decode, but whats with that dirty –? I can't find a way to decode that character properly (i think it's supposed to be a hyphen from looking at my osx mail client).

If anyone can help me with this that would be wonderful!
 
Last edited:
Dj_Jestar said:
Are you setting your form, page, and header charset to UTF-8?

er, not that I know of! Here is my code:

Code:
			// Get subject via multipart decode
			$subj_elements = imap_mime_header_decode($val -> subject);
			$subj_full = "";
			for ($i = 0; $i < count($subj_elements); $i++)
				$subj_full .= $subj_elements[$i] -> text;

			// Limit string lengths
			if (strlen($subj_full) > $subject_length)
				$subj = substr($subj_full, 0, ($subject_length - 1)) ."...";
			else
				$subj = $subj_full;

			echo $subj;

It works 99% of the time, but just sometimes I get those wierd chars that were not decoded properly. Did you know how to sort them out?
 
On your HTML page/form, do you have the following (or similar) within the <head></head> tags?

Code:
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">

Or within the script that presents the form, do you have a header line such as:

Code:
<?php
header("Content-type: text/html; charset=utf-8");
?>
 
No, it's unnecesary as I should be converting the utf-8 into plain text, via the imap_mime_header_decode function.

Edit: I seen to have fixed it now, though I don't know what I did! :rolleyes:
 
Last edited:
Back
Top Bottom