note 73749 added to function.iconv
| From: | GeorgiosPapadakis at osu1 dot php dot net | Date: | Thu, 08 Mar 2007 20:28:53 +0000 |
| Subject: | note 73749 added to function.iconv | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-124245@lists.php.net to get a copy of this message | ||
Many mail servers don't handle utf-8 correctly as they assume iso-8859-x encodings, so you
would want to convert the headers, subject and body of an email prior to sending it out.
If iconv() and mb_convert_encoding() are missing the following function can be used to convert UTF8
to iso-8859-7 encoding. It discards all characters that are not 2-byte greek characters or
single-byte (ascii).
<?php
function conv_utf8_iso8859_7($s) {
$len = strlen($s);
$out = "";
$curr_char = "";
for($i=0; $i < $len; $i++) {
$curr_char .= $s[$i];
if( ( ord($s[$i]) & (128+64) ) == 128) {
//character end found
if ( strlen($curr_char) == 2) {
// 2-byte character check for it is greek one and convert
if (ord($curr_char[0])==205) $out .= chr( ord($curr_char[1])+16 );
else if (ord($curr_char[0])==206) $out .= chr( ord($curr_char[1])+48 );
else if (ord($curr_char[0])==207) $out .= chr( ord($curr_char[1])+112 );
else ; // non greek 2-byte character, discard character
} else ;// n-byte character, n>2, discard character
$curr_char = "";
} else if (ord($s[$i]) < 128) {
// character is one byte (ascii)
$out .= $curr_char;
$curr_char = "";
}
}
return $out;
}
?>
----
Server IP: 62.103.148.26
Probable Submitter: 62.1.107.191
----
Manual Page -- http://www.php.net/manual/en/function.iconv.php
Edit -- https://master.php.net/note/edit/73749
Del: integrated -- https://master.php.net/note/delete/73749/integrated
Del: useless -- https://master.php.net/note/delete/73749/useless
Del: bad code -- https://master.php.net/note/delete/73749/bad+code
Del: spam -- https://master.php.net/note/delete/73749/spam
Del: non-english -- https://master.php.net/note/delete/73749/non-english
Del: in docs -- https://master.php.net/note/delete/73749/in+docs
Del: other reasons-- https://master.php.net/note/delete/73749
Reject -- https://master.php.net/note/reject/73749
Search -- https://master.php.net/manage/user-notes.php