Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // L = Latin 1
- // G = Greek
- // C = Cyrillic
- // E = Central Europe
- // T = Turkish
- // B = Baltic
- // J = Japanese
- // S = Simplified Chinese
- // K = Korean
- // H = Traditional Chinese
- function codepage_convert ($str, $conv_to = 'UTF-8') {
- $sets = array ('L' => 'CP1252',
- 'G' => 'ISO-8859-7',
- 'C' => 'CP1251',
- 'E' => 'ISO-8859-2',
- 'T' => 'ISO-8859-9',
- 'B' => 'ISO-8859-13',
- 'J' => 'SJIS-win',
- 'S' => 'CP936',
- 'K' => 'CP949',
- 'H' => 'CP950');
- $tr_ptrn = array ("/\^d/", "/\^s/", "/\^c/", "/\^a/", "/\^q/", "/\^t/", "/\^l/", "/\^r/", "/\^v/");
- $tr_ptrn_r = array ("\\", "/", ":", "*", "?", "\"", "<", ">", "|");
- $str = preg_replace ($tr_ptrn, $tr_ptrn_r, $str);
- $newstr = $tmp = '';
- $current_cp = 'L';
- $len = strlen ($str);
- for ($i=0; $i<$len; $i++) {
- if ($str{$i} == '^' && isset ($sets[$str{$i+1}]) && $str{$i-1} != "^") {
- if ($tmp != '') {
- $newstr .= mb_convert_encoding ($tmp, $conv_to, $sets[$current_cp]);
- //$newstr .= iconv($sets[$current_cp], $conv_to, $tmp);
- $tmp = '';
- }
- $current_cp = $str{++$i};
- }
- // Filter out every character below 0x20
- else if (ord ($str{$i}) > 31)
- $tmp .= $str{$i};
- }
- if ($tmp != '')
- $newstr .= mb_convert_encoding ($tmp, $conv_to, $sets[$current_cp]);
- // Final special char to convert - could not do that before codepage conversion
- return str_replace ('^^', '^', $newstr);
- }
- function lfs_str_convert($str) // ???? ?????? ?????? ?????
- {
- $str = codepage_convert($str);
- // Replace Set
- $replaceArray = array('000000','FF0000','00FF00','FFFF00','0000FF','FF00FF','00FFFF','FFFFFF');
- // Extra State Information
- $isTagOpen = FALSE;
- // Parse String
- for ($i = 0, $j = 1, $l = strlen($str); $i < $l; ++$i, ++$j)
- {
- /* Handle Color Codes */
- if ($str{$i} == '^' && is_numeric($str{$j}))
- {
- if ($isTagOpen == TRUE)
- {
- // Set State.
- $isTagOpen = FALSE;
- // Inject Close Tag
- $str = substr($str, 0, $i) . '</span>' . substr($str, $i);
- // Move Str pointers Past ?.
- $i += 7; $j += 7; $l = strlen($str);
- }
- if ($str{$j} < 8)
- {
- // Set State
- $isTagOpen = TRUE;
- // Inject HTML Markup
- $str = substr($str, 0, $i) . '<span style="color:#'.$replaceArray[$str[$j]].';">' . substr($str, $i);
- // Move Pointer Past The Change.
- $i += 29; $j += 29;
- // Get new String Length.
- $l = strlen($str);
- }
- // Remove The Formatting.
- $str = substr($str,0,$i).substr($str,$j+1);
- // $str[$i] = NULL; # Remove ^.
- // $str[$j] = NULL; # Remove Int.
- }
- }
- // Close any tag left open.
- if ($isTagOpen)
- $str .= '</span>';
- return $str;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement