Advertisement
repeat83

Untitled

Oct 28th, 2015
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. <?php
  2. // L = Latin 1
  3. // G = Greek
  4. // C = Cyrillic
  5. // E = Central Europe
  6. // T = Turkish
  7. // B = Baltic
  8. // J = Japanese
  9. // S = Simplified Chinese
  10. // K = Korean
  11. // H = Traditional Chinese
  12. function codepage_convert ($str, $conv_to = 'UTF-8') {
  13. $sets = array ('L' => 'CP1252',
  14. 'G' => 'ISO-8859-7',
  15. 'C' => 'CP1251',
  16. 'E' => 'ISO-8859-2',
  17. 'T' => 'ISO-8859-9',
  18. 'B' => 'ISO-8859-13',
  19. 'J' => 'SJIS-win',
  20. 'S' => 'CP936',
  21. 'K' => 'CP949',
  22. 'H' => 'CP950');
  23.  
  24. $tr_ptrn = array ("/\^d/", "/\^s/", "/\^c/", "/\^a/", "/\^q/", "/\^t/", "/\^l/", "/\^r/", "/\^v/");
  25. $tr_ptrn_r = array ("\\", "/", ":", "*", "?", "\"", "<", ">", "|");
  26. $str = preg_replace ($tr_ptrn, $tr_ptrn_r, $str);
  27.  
  28. $newstr = $tmp = '';
  29. $current_cp = 'L';
  30. $len = strlen ($str);
  31. for ($i=0; $i<$len; $i++) {
  32. if ($str{$i} == '^' && isset ($sets[$str{$i+1}]) && $str{$i-1} != "^") {
  33. if ($tmp != '') {
  34. $newstr .= mb_convert_encoding ($tmp, $conv_to, $sets[$current_cp]);
  35. //$newstr .= iconv($sets[$current_cp], $conv_to, $tmp);
  36. $tmp = '';
  37. }
  38. $current_cp = $str{++$i};
  39. }
  40. // Filter out every character below 0x20
  41. else if (ord ($str{$i}) > 31)
  42. $tmp .= $str{$i};
  43. }
  44. if ($tmp != '')
  45. $newstr .= mb_convert_encoding ($tmp, $conv_to, $sets[$current_cp]);
  46.  
  47. // Final special char to convert - could not do that before codepage conversion
  48. return str_replace ('^^', '^', $newstr);
  49. }
  50.  
  51. function lfs_str_convert($str) // ???? ?????? ?????? ?????
  52. {
  53. $str = codepage_convert($str);
  54. // Replace Set
  55. $replaceArray = array('000000','FF0000','00FF00','FFFF00','0000FF','FF00FF','00FFFF','FFFFFF');
  56. // Extra State Information
  57. $isTagOpen = FALSE;
  58. // Parse String
  59. for ($i = 0, $j = 1, $l = strlen($str); $i < $l; ++$i, ++$j)
  60. {
  61. /* Handle Color Codes */
  62. if ($str{$i} == '^' && is_numeric($str{$j}))
  63. {
  64. if ($isTagOpen == TRUE)
  65. {
  66. // Set State.
  67. $isTagOpen = FALSE;
  68. // Inject Close Tag
  69. $str = substr($str, 0, $i) . '</span>' . substr($str, $i);
  70. // Move Str pointers Past ?.
  71. $i += 7; $j += 7; $l = strlen($str);
  72. }
  73. if ($str{$j} < 8)
  74. {
  75. // Set State
  76. $isTagOpen = TRUE;
  77. // Inject HTML Markup
  78. $str = substr($str, 0, $i) . '<span style="color:#'.$replaceArray[$str[$j]].';">' . substr($str, $i);
  79. // Move Pointer Past The Change.
  80. $i += 29; $j += 29;
  81. // Get new String Length.
  82. $l = strlen($str);
  83. }
  84. // Remove The Formatting.
  85. $str = substr($str,0,$i).substr($str,$j+1);
  86. // $str[$i] = NULL; # Remove ^.
  87. // $str[$j] = NULL; # Remove Int.
  88. }
  89. }
  90. // Close any tag left open.
  91. if ($isTagOpen)
  92. $str .= '</span>';
  93. return $str;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement