Changeset 635 for trunk/Common/UTF8.php
- Timestamp:
- Jan 19, 2014, 9:36:28 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Common/UTF8.php
r548 r635 31 31 */ 32 32 33 $CharTable = array( 33 class Encoding 34 { 35 function __construct() 36 { 37 $this->CharTable = array( 34 38 'iso2' => array( 35 39 0x80=>"\xc2\x80", … … 520 524 ), 521 525 ); 522 523 524 function ToUTF8($String, $Charset = 'iso2') 525 { 526 global $CharTable; 527 528 $Result = ''; 529 for($I = 0; $I < strlen($String); $I++) 526 } 527 528 function ToUTF8($String, $Charset = 'iso2') 530 529 { 531 if(ord($String[$I]) < 128) $Result .= $String[$I]; 532 else if(ord($String[$I]) > 127) 533 { 534 $Result .= $CharTable[$Charset][ord($String[$I])]; 535 } 530 $Result = ''; 531 for($I = 0; $I < strlen($String); $I++) 532 { 533 if(ord($String[$I]) < 128) $Result .= $String[$I]; 534 else if(ord($String[$I]) > 127) 535 { 536 $Result .= $this->CharTable[$Charset][ord($String[$I])]; 537 } 538 } 539 return($Result); 536 540 } 537 return($Result); 541 542 function FromUTF8($String, $Charset = 'iso2') 543 { 544 $Result = ''; 545 $UTFPrefix = ''; 546 for($I = 0; $I < strlen($String); $I++) 547 { 548 if(ord($String{$I}) & 0x80) // UTF control character 549 { 550 if(ord($String{$I}) & 0x40) // First 551 { 552 if($UTFPrefix != '') $Result .= chr(array_search($UTFPrefix, $this->CharTable[$Charset])); 553 $UTFPrefix = $String{$I}; 554 } 555 else $UTFPrefix .= $String{$I}; // Next 556 } else 557 { 558 if($UTFPrefix != '') $Result .= chr(array_search($UTFPrefix, $this->CharTable[$Charset])); 559 $UTFPrefix = ''; 560 $Result .= $String{$I}; 561 } 562 } 563 return($Result); 564 } 538 565 } 539 540 function FromUTF8($String, $Charset = 'iso2')541 {542 global $CharTable;543 544 $Result = '';545 $UTFPrefix = '';546 for($I = 0; $I < strlen($String); $I++)547 {548 if(ord($String{$I}) & 0x80) // UTF control character549 {550 if(ord($String{$I}) & 0x40) // First551 {552 if($UTFPrefix != '') $Result .= chr(array_search($UTFPrefix, $CharTable[$Charset]));553 $UTFPrefix = $String{$I};554 }555 else $UTFPrefix .= $String{$I}; // Next556 } else557 {558 if($UTFPrefix != '') $Result .= chr(array_search($UTFPrefix, $CharTable[$Charset]));559 $UTFPrefix = '';560 $Result .= $String{$I};561 }562 }563 return($Result);564 }
Note:
See TracChangeset
for help on using the changeset viewer.