php-i18n Digest 11 Nov 2004 14:58:26 -0000 Issue 259
Topics (messages 786 through 790):
Re: How to get WIN-1255 encoded string
786 by: Manuel Lemos
787 by: Fredrik Tolf
788 by: Fredrik Tolf
790 by: shimi
locale weirdness when launching a bash script from PHP exec()
789 by: Alexandre Aractingi
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[EMAIL PROTECTED]
----------------------------------------------------------------------
--- Begin Message ---
Hello,
On 11/07/2004 09:57 AM, Marina Markus wrote:
I am desperately looking for a solution of a problem that seems quite
simple.
I need a PHP script to create an email message in a way that a subject line
in Hebrew will be readable in all mail clients. Some mail clients cannot
cope with Hebrew if they don't have character set explicitly denoted.
Is there a possibility in PHP allowing to encode a string
with WIN-1255 character set encoding? The result should look like:
=?windows-1255?B?Rlc6IOz26eHl+CDk8uXj6e0=?=
which the mail client then is able to decode back into Hebrew.
You can use this class for that purpose easily. Just set the
default_charset class variable to that windows-1255 and the class will
compose and send the message assuming that text in the body and in the
headers are encoded that way.
http://www.phpclasses.org/mimemessage
--
Regards,
Manuel Lemos
PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/
PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/
Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html
--- End Message ---
--- Begin Message ---
On Sun, 2004-11-07 at 13:57 +0200, Marina Markus wrote:
> Hello,
Hi!
> I need a PHP script to create an email message in a way that a subject line
> in Hebrew will be readable in all mail clients. Some mail clients cannot
> cope with Hebrew if they don't have character set explicitly denoted.
I believe that should be _all_ e-mail clients. Since the default MIME
charset is US-ASCII (as per RFC 2047 and 2822), only faulty e-mail
clients would be able to cope with non-ASCII characters without wrapping
the header in MIME.
> Is there a possibility in PHP allowing to encode a string
> with WIN-1255 character set encoding? The result should look like:
>
> =?windows-1255?B?Rlc6IOz26eHl+CDk8uXj6e0=?=
>
> which the mail client then is able to decode back into Hebrew.
If you're running PHP5, you might want to look at iconv_mime_encode. If
not, you can take these functions, which are from a GPL:d webmail I'm
writing, and adapt them to your purpose:
function mimifyhdr($header)
{
if(strpos($header, " ") !== FALSE)
{
$temp = "";
$cp = 0;
while(($np = strpos($header, " ", $cp)) !== FALSE)
{
$temp .= mimifyhdr(substr($header, $cp, $np - $cp)) . " ";
$cp = $np + 1;
}
$temp .= mimifyhdr(substr($header, $cp));
return($temp);
}
$nh = "";
$num = 0;
for($i = 0; $i < strlen($header); $i++)
{
$c = substr($header, $i, 1);
if(ord($c) >= 128)
$num++;
}
if($num == 0)
return($header);
if($num > (strlen($header) / 4))
return("=?UTF-8?B?" . encodemime($header, "base64") . "?=");
$nt = "";
for($i = 0; $i < strlen($header); $i++)
{
$c = substr($header, $i, 1);
if(($c == "=") || (ord($c) >= 128) || ($c == "_"))
{
$nt .= "=" . strtoupper(dechex(ord($c)));
} else if($c == " ") {
$nt .= "_";
} else {
$nt .= $c;
}
}
return("=?UTF-8?Q?" . $nt . "?=");
}
function addhdr($name, $val)
{
global $headers;
if(trim($val) != "")
{
$temp .= $name . ": " . mimifyhdr($val);
$maxlen = strlen($temp);
$ls = 0;
while($maxlen > 70)
{
$cp = $ls + 70;
while(strpos("\t ", substr($temp, $cp, 1)) === FALSE)
{
if(--$cp < $ls)
break;
}
if($cp < $ls)
break;
$temp = substr($temp, 0, $cp) . "\r\n\t" .
substr($temp, $cp+ 1);
$ls = $cp + 3;
$maxlen = strlen($temp) - $ls;
}
$headers .= $temp . "\r\n";
}
}
Note that they take values which are already in the UTF-8 encoding. If
your values aren't in UTF-8, take a look at the iconv function.
> If anyone has a solution for another character set, I suppose it can also
> help.
I'd recommend that you use UTF-8 instead. It's more general than
Windows-1255 (copes with characters outside the Hebrew range), and is
probably supported by more MUAs.
Hope it helps!
Fredrik Tolf
--- End Message ---
--- Begin Message ---
On Sun, 2004-11-07 at 20:42 +0100, Fredrik Tolf wrote:
> On Sun, 2004-11-07 at 13:57 +0200, Marina Markus wrote:
> > Is there a possibility in PHP allowing to encode a string
> > with WIN-1255 character set encoding? The result should look like:
> >
> > =?windows-1255?B?Rlc6IOz26eHl+CDk8uXj6e0=?=
> >
> > which the mail client then is able to decode back into Hebrew.
>
> If you're running PHP5, you might want to look at iconv_mime_encode. If
> not, you can take these functions, which are from a GPL:d webmail I'm
> writing, and adapt them to your purpose:
> [snip]
> return("=?UTF-8?B?" . encodemime($header, "base64") . "?=");
> [snip]
Sorry, it seems the `encodemime' function was mine as well:
function encodemime($text, $encoding)
{
if($encoding == "quoted-printable")
{
$nt = "";
for($i = 0; $i < strlen($text); $i++)
{
$c = substr($text, $i, 1);
if(($c == "=") || (ord($c) >= 128))
$nt .= "=" . dechex(ord($c));
else
$nt .= $c;
}
return($nt);
}
if($encoding == "base64")
return(base64_encode($text));
return($text);
}
Sorry for taking two mails.
Fredrik Tolf
--- End Message ---
--- Begin Message ---
>From what I've seen, if someone mails me a correctly formatted message,
I get the title right, however something like a non-standard mail
clients does it, I get the =windows-1255 string you gave as the subject.
Do note: The standard name is ISO-8859-8-I. NOT windows-1255, which is a
nice micro$oft invention, but not something standard, which is why not
each and every mail client will support it.
I believe I did it "The Right Way" (TM) in my site by adding the
following header to the mail() function:
Content-Type: text/html; charset="ISO-8859-8-I"
You might want to try that... it works for me everywhere (including in
completely English mail clients under Linux)
Shimi
On Sun, 2004-11-07 at 13:57, Marina Markus wrote:
> Hello,
>
> I am desperately looking for a solution of a problem that seems quite
> simple.
>
> I need a PHP script to create an email message in a way that a subject line
> in Hebrew will be readable in all mail clients. Some mail clients cannot
> cope with Hebrew if they don't have character set explicitly denoted.
>
> Is there a possibility in PHP allowing to encode a string
> with WIN-1255 character set encoding? The result should look like:
>
> =?windows-1255?B?Rlc6IOz26eHl+CDk8uXj6e0=?=
>
> which the mail client then is able to decode back into Hebrew.
>
> If anyone has a solution for another character set, I suppose it can also
> help.
>
> Will be grateful for any hint or idea.
> Marina Markus
> [EMAIL PROTECTED]
>
>
--
Never forget that:
1. "Sure UNIX is user-friendly! It's just picky about who its friends
are!"
2. "The day that Microsoft make a product that doesn't suck,
is the day they start making vacuum cleaners.."
3. "Windows is a 32bit port for a 16bit GUI for an 8bit OS made for a
4bit CPU by a 2bit company that can't stand 1bit of competition!"
--- End Message ---
--- Begin Message ---
Hi all,
I don't know yet if the problem is related to PHP or to Apache, but here
it is:
I have a PHP4 page that passes arguments to a bash script (Apache is
running on Debian by the way) through the exec() function. These
arguments can include locale characters (like the French "�" for
example).
I noticed that these characters are messed up when passed to the bash
script, although on my Mandrake laptop (that I installed in French - my
Debian server was installed in English), everything is passed correctly.
I don't know which parameter to tune to get the exec() function to keep
the locale chars ok, any idea? (would changing the $LANG to fr_FR do any
good?)
Thanks in advance,
--
Alexandre Aractingi <[EMAIL PROTECTED]>
--- End Message ---