home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / admin / EUC-JP.inc < prev    next >
Encoding:
Text File  |  2003-06-29  |  2.0 KB  |  82 lines

  1. <?php
  2. /////////////////////////////
  3. //    X-EUC-JP.inc
  4. //    (C)2001-2002 Ryo Chijiiwa <Ryo@IlohaMail.org>
  5. //        
  6. //        Description:
  7. //                Charset conversion library for Japanese text.
  8. //                Converts JIS (used in email) to X-EUC-JP (used for web pages),
  9. //                and X-EUC-JP (submitted by web forms) to JIS (used in email).
  10. //        
  11. //        Contributions:
  12. //                TOMO <groove@spencernetwork.org>: jcode.php
  13. //
  14. //    This file is part of IlohaMail. IlohaMail is free software released 
  15. //    under the GPL license.  See enclosed file COPYING for details, or 
  16. //    see http://www.fsf.org/copyleft/gpl.html
  17. ////////////////////////////
  18.  
  19. include("../lang/jp/jcode.inc");
  20. include_once("../include/qp_enc.inc");
  21.  
  22. function LangIs8Bit($string){
  23.     $len = strlen($string);
  24.     for ($i=0; $i < $len; $i++)
  25.         if (ord($string[$i])>=128) return true;
  26.     
  27.     return false;
  28. }
  29.  
  30. function LangConvert($string, $charset, $from_charset){
  31.     if (!stristr($from_charset, "jp")){
  32.         return $string;
  33.     }else if (strcasecmp($charset, "x-euc-jp")==0){
  34.         return JcodeConvert($string, 0, 1);
  35.     }else{
  36.         return $string;
  37.     }
  38. }
  39.  
  40. function LangEncodeSubject($input, $charset){
  41.     $subject=$input;
  42.     if (strcasecmp($charset, "x-euc-jp")==0){
  43.         $charset_code = AutoDetect($input);
  44.         if (($charset_code > 0) && ($charset_code < 3)){
  45.             $subject=JcodeConvert($subject,0,3);
  46.             $subject="=?ISO-2022-JP?B?".base64_encode($subject)."?=";        
  47.         }else if (LangIS8Bit($subject)){
  48.             $subject = "=?ISO-8859-1?Q?".qp_enc($subject)."?=";
  49.         }
  50.     }
  51.     
  52.     return $subject;
  53. }
  54.  
  55. function LangEncodeMessage($input, $charset){
  56.     $message=$input;
  57.     
  58.     $result["type"]="Content-Type: text/plain; charset=\"us-ascii\"\r\n";    
  59.     $result["data"]=$message;
  60.     
  61.     if (strcasecmp($charset, "x-euc-jp")==0){
  62.         $charset_code = AutoDetect($message);
  63.         if ($charset_code > 0){
  64.             $result["type"]="Content-Type: text/plain; charset=ISO-2022-JP\r\n";
  65.              $result["encoding"]="Content-Transfer-Encoding: 7bit\r\n";
  66.              $result["data"] = JcodeConvert($message,0,3);
  67.         }else{
  68.             $result["data"] = $message;
  69.         }        
  70.     }
  71.     
  72.     return $result;
  73. }
  74.  
  75. include_once("../lang/common.inc");
  76.  
  77. function LangWrap($str){
  78.     return $str;
  79. }
  80.  
  81. ?>
  82.