PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/ConvertCharset.class.php

https://github.com/nielsrune/saldi
PHP | 603 lines | 251 code | 19 blank | 333 comment | 70 complexity | cece610da0e7ebd62fdf1a31c6daad9d MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /**
  3. * @author Mikolaj Jedrzejak <mikolajj@op.pl>
  4. * @copyright Copyright Mikolaj Jedrzejak (c) 2003-2004
  5. * @version 1.0 2004-07-27 00:37
  6. * @link http://www.unicode.org Unicode Homepage
  7. * @link http://www.mikkom.pl My Homepage
  8. *
  9. **/
  10. $PATH_TO_CLASS = dirname(ereg_replace("\\\\","/",__FILE__)) . "/" . "ConvertTables" . "/";
  11. define ("CONVERT_TABLES_DIR", $PATH_TO_CLASS);
  12. define ("DEBUG_MODE", 1);
  13. /**
  14. * -- 1.0 2004-07-28 --
  15. *
  16. * -- The most important thing --
  17. * I want to thank all people who helped me fix all bugs, small and big once.
  18. * I hope that you don't mind that your names are in this file.
  19. *
  20. * -- Some Apache issues --
  21. * I get info from Lukas Lisa, that in some cases with special apache configuration
  22. * you have to put header() function with proper encoding to get your result
  23. * displayed correctly.
  24. * If you want to see what I mean, go to demo.php and demo1.php
  25. *
  26. * -- BETA 1.0 2003-10-21 --
  27. *
  28. * -- You should know about... --
  29. * For good understanding this class you shouls read all this stuff first :) but if you are
  30. * in a hurry just start the demo.php and see what's inside.
  31. * 1. That I'm not good in english at 03:45 :) - so forgive me all mistakes
  32. * 2. This class is a BETA version because I haven't tested it enough
  33. * 3. Feel free to contact me with questions, bug reports and mistakes in PHP and this documentation (email below)
  34. *
  35. * -- In a few words... --
  36. * Why ConvertCharset class?
  37. *
  38. * I have made this class because I had a lot of problems with diferent charsets. First because people
  39. * from Microsoft wanted to have thair own encoding, second because people from Macromedia didn't
  40. * thought about other languages, third because sometimes I need to use text written on MAC, and of course
  41. * it has its own encoding :)
  42. *
  43. * Notice & remember:
  44. * - When I'm saying 1 byte string I mean 1 byte per char.
  45. * - When I'm saying multibyte string I mean more than one byte per char.
  46. *
  47. * So, this are main FEATURES of this class:
  48. * - conversion between 1 byte charsets
  49. * - conversion from 1 byte to multi byte charset (utf-8)
  50. * - conversion from multibyte charset (utf-8) to 1 byte charset
  51. * - every conversion output can be save with numeric entities (browser charset independent - not a full truth)
  52. *
  53. * This is a list of charsets you can operate with, the basic rule is that a char have to be in both charsets,
  54. * otherwise you'll get an error.
  55. *
  56. * - WINDOWS
  57. * - windows-1250 - Central Europe
  58. * - windows-1251 - Cyrillic
  59. * - windows-1252 - Latin I
  60. * - windows-1253 - Greek
  61. * - windows-1254 - Turkish
  62. * - windows-1255 - Hebrew
  63. * - windows-1256 - Arabic
  64. * - windows-1257 - Baltic
  65. * - windows-1258 - Viet Nam
  66. * - cp874 - Thai - this file is also for DOS
  67. *
  68. * - DOS
  69. * - cp437 - Latin US
  70. * - cp737 - Greek
  71. * - cp775 - BaltRim
  72. * - cp850 - Latin1
  73. * - cp852 - Latin2
  74. * - cp855 - Cyrylic
  75. * - cp857 - Turkish
  76. * - cp860 - Portuguese
  77. * - cp861 - Iceland
  78. * - cp862 - Hebrew
  79. * - cp863 - Canada
  80. * - cp864 - Arabic
  81. * - cp865 - Nordic
  82. * - cp866 - Cyrylic Russian (this is the one, used in IE "Cyrillic (DOS)" )
  83. * - cp869 - Greek2
  84. *
  85. * - MAC (Apple)
  86. * - x-mac-cyrillic
  87. * - x-mac-greek
  88. * - x-mac-icelandic
  89. * - x-mac-ce
  90. * - x-mac-roman
  91. *
  92. * - ISO (Unix/Linux)
  93. * - iso-8859-1
  94. * - iso-8859-2
  95. * - iso-8859-3
  96. * - iso-8859-4
  97. * - iso-8859-5
  98. * - iso-8859-6
  99. * - iso-8859-7
  100. * - iso-8859-8
  101. * - iso-8859-9
  102. * - iso-8859-10
  103. * - iso-8859-11
  104. * - iso-8859-12
  105. * - iso-8859-13
  106. * - iso-8859-14
  107. * - iso-8859-15
  108. * - iso-8859-16
  109. *
  110. * - MISCELLANEOUS
  111. * - gsm0338 (ETSI GSM 03.38)
  112. * - cp037
  113. * - cp424
  114. * - cp500
  115. * - cp856
  116. * - cp875
  117. * - cp1006
  118. * - cp1026
  119. * - koi8-r (Cyrillic)
  120. * - koi8-u (Cyrillic Ukrainian)
  121. * - nextstep
  122. * - us-ascii
  123. * - us-ascii-quotes
  124. *
  125. * - DSP implementation for NeXT
  126. * - stdenc
  127. * - symbol
  128. * - zdingbat
  129. *
  130. * - And specially for old Polish programs
  131. * - mazovia
  132. *
  133. * -- Now, to the point... --
  134. * Here are main variables.
  135. *
  136. * DEBUG_MODE
  137. *
  138. * You can set this value to:
  139. * - -1 - No errors or comments
  140. * - 0 - Only error messages, no comments
  141. * - 1 - Error messages and comments
  142. *
  143. * Default value is 1, and during first steps with class it should be left as is.
  144. *
  145. * CONVERT_TABLES_DIR
  146. *
  147. * This is a place where you store all files with charset encodings. Filenames should have
  148. * the same names as encodings. My advise is to keep existing names, because thay
  149. * were taken from unicode.org (www.unicode.org), and after update to unicode 3.0 or 4.0
  150. * the names of files will be the same, so if you want to save your time...uff, leave the
  151. * names as thay are for future updates.
  152. *
  153. * The directory with edings files should be in a class location directory by default,
  154. * but of course you can change it if you like.
  155. *
  156. * @package All about charset...
  157. * @author Mikolaj Jedrzejak <mikolajj@op.pl>
  158. * @copyright Copyright Mikolaj Jedrzejak (c) 2003-2004
  159. * @version 1.0 2004-07-27 23:11
  160. * @access public
  161. *
  162. * @link http://www.unicode.org Unicode Homepage
  163. **/
  164. class ConvertCharset {
  165. var $RecognizedEncoding; //This value keeps information if string contains multibyte chars.
  166. var $Entities; // This value keeps information if output should be with numeric entities.
  167. /**
  168. * CharsetChange::NumUnicodeEntity()
  169. *
  170. * Unicode encoding bytes, bits representation.
  171. * Each b represents a bit that can be used to store character data.
  172. * - bytes, bits, binary representation
  173. * - 1, 7, 0bbbbbbb
  174. * - 2, 11, 110bbbbb 10bbbbbb
  175. * - 3, 16, 1110bbbb 10bbbbbb 10bbbbbb
  176. * - 4, 21, 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb
  177. *
  178. * This function is written in a "long" way, for everyone who woluld like to analize
  179. * the process of unicode encoding and understand it. All other functions like HexToUtf
  180. * will be written in a "shortest" way I can write tham :) it does'n mean thay are short
  181. * of course. You can chech it in HexToUtf() (link below) - very similar function.
  182. *
  183. * IMPORTANT: Remember that $UnicodeString input CANNOT have single byte upper half
  184. * extended ASCII codes, why? Because there is a posibility that this function will eat
  185. * the following char thinking it's miltibyte unicode char.
  186. *
  187. * @param string $UnicodeString Input Unicode string (1 char can take more than 1 byte)
  188. * @return string This is an input string olso with unicode chars, bus saved as entities
  189. * @see HexToUtf()
  190. **/
  191. function UnicodeEntity ($UnicodeString)
  192. {
  193. $OutString = "";
  194. $StringLenght = strlen ($UnicodeString);
  195. for ($CharPosition = 0; $CharPosition < $StringLenght; $CharPosition++)
  196. {
  197. $Char = $UnicodeString [$CharPosition];
  198. $AsciiChar = ord ($Char);
  199. if ($AsciiChar < 128) //1 7 0bbbbbbb (127)
  200. {
  201. $OutString .= $Char;
  202. }
  203. else if ($AsciiChar >> 5 == 6) //2 11 110bbbbb 10bbbbbb (2047)
  204. {
  205. $FirstByte = ($AsciiChar & 31);
  206. $CharPosition++;
  207. $Char = $UnicodeString [$CharPosition];
  208. $AsciiChar = ord ($Char);
  209. $SecondByte = ($AsciiChar & 63);
  210. $AsciiChar = ($FirstByte * 64) + $SecondByte;
  211. $Entity = sprintf ("&#%d;", $AsciiChar);
  212. $OutString .= $Entity;
  213. }
  214. else if ($AsciiChar >> 4 == 14) //3 16 1110bbbb 10bbbbbb 10bbbbbb
  215. {
  216. $FirstByte = ($AsciiChar & 31);
  217. $CharPosition++;
  218. $Char = $UnicodeString [$CharPosition];
  219. $AsciiChar = ord ($Char);
  220. $SecondByte = ($AsciiChar & 63);
  221. $CharPosition++;
  222. $Char = $UnicodeString [$CharPosition];
  223. $AsciiChar = ord ($Char);
  224. $ThidrByte = ($AsciiChar & 63);
  225. $AsciiChar = ((($FirstByte * 64) + $SecondByte) * 64) + $ThidrByte;
  226. $Entity = sprintf ("&#%d;", $AsciiChar);
  227. $OutString .= $Entity;
  228. }
  229. else if ($AsciiChar >> 3 == 30) //4 21 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb
  230. {
  231. $FirstByte = ($AsciiChar & 31);
  232. $CharPosition++;
  233. $Char = $UnicodeString [$CharPosition];
  234. $AsciiChar = ord ($Char);
  235. $SecondByte = ($AsciiChar & 63);
  236. $CharPosition++;
  237. $Char = $UnicodeString [$CharPosition];
  238. $AsciiChar = ord ($Char);
  239. $ThidrByte = ($AsciiChar & 63);
  240. $CharPosition++;
  241. $Char = $UnicodeString [$CharPosition];
  242. $AsciiChar = ord ($Char);
  243. $FourthByte = ($AsciiChar & 63);
  244. $AsciiChar = ((((($FirstByte * 64) + $SecondByte) * 64) + $ThidrByte) * 64) + $FourthByte;
  245. $Entity = sprintf ("&#%d;", $AsciiChar);
  246. $OutString .= $Entity;
  247. }
  248. }
  249. return $OutString;
  250. }
  251. /**
  252. * ConvertCharset::HexToUtf()
  253. *
  254. * This simple function gets unicode char up to 4 bytes and return it as a regular char.
  255. * It is very similar to UnicodeEntity function (link below). There is one difference
  256. * in returned format. This time it's a regular char(s), in most cases it will be one or two chars.
  257. *
  258. * @param string $UtfCharInHex Hexadecimal value of a unicode char.
  259. * @return string Encoded hexadecimal value as a regular char.
  260. * @see UnicodeEntity()
  261. **/
  262. function HexToUtf ($UtfCharInHex)
  263. {
  264. $OutputChar = "";
  265. $UtfCharInDec = hexdec($UtfCharInHex);
  266. if($UtfCharInDec<128) $OutputChar .= chr($UtfCharInDec);
  267. else if($UtfCharInDec<2048)$OutputChar .= chr(($UtfCharInDec>>6)+192).chr(($UtfCharInDec&63)+128);
  268. else if($UtfCharInDec<65536)$OutputChar .= chr(($UtfCharInDec>>12)+224).chr((($UtfCharInDec>>6)&63)+128).chr(($UtfCharInDec&63)+128);
  269. else if($UtfCharInDec<2097152)$OutputChar .= chr($UtfCharInDec>>18+240).chr((($UtfCharInDec>>12)&63)+128).chr(($UtfCharInDec>>6)&63+128). chr($UtfCharInDec&63+128);
  270. return $OutputChar;
  271. }
  272. /**
  273. * CharsetChange::MakeConvertTable()
  274. *
  275. * This function creates table with two SBCS (Single Byte Character Set). Every conversion
  276. * is through this table.
  277. *
  278. * - The file with encoding tables have to be save in "Format A" of unicode.org charset table format! This is usualy writen in a header of every charset file.
  279. * - BOTH charsets MUST be SBCS
  280. * - The files with encoding tables have to be complet (Non of chars can be missing, unles you are sure you are not going to use it)
  281. *
  282. * "Format A" encoding file, if you have to build it by yourself should aplly these rules:
  283. * - you can comment everything with #
  284. * - first column contains 1 byte chars in hex starting from 0x..
  285. * - second column contains unicode equivalent in hex starting from 0x....
  286. * - then every next column is optional, but in "Format A" it should contain unicode char name or/and your own comment
  287. * - the columns can be splited by "spaces", "tabs", "," or any combination of these
  288. * - below is an example
  289. *
  290. * <code>
  291. * #
  292. * # The entries are in ANSI X3.4 order.
  293. * #
  294. * 0x00 0x0000 # NULL end extra comment, if needed
  295. * 0x01 0x0001 # START OF HEADING
  296. * # Oh, one more thing, you can make comments inside of a rows if you like.
  297. * 0x02 0x0002 # START OF TEXT
  298. * 0x03 0x0003 # END OF TEXT
  299. * next line, and so on...
  300. * </code>
  301. *
  302. * You can get full tables with encodings from http://www.unicode.org
  303. *
  304. * @param string $FirstEncoding Name of first encoding and first encoding filename (thay have to be the same)
  305. * @param string $SecondEncoding Name of second encoding and second encoding filename (thay have to be the same). Optional for building a joined table.
  306. * @return array Table necessary to change one encoding to another.
  307. **/
  308. function MakeConvertTable ($FirstEncoding, $SecondEncoding = "")
  309. {
  310. $ConvertTable = array();
  311. for($i = 0; $i < func_num_args(); $i++)
  312. {
  313. /**
  314. * Because func_*** can't be used inside of another function call
  315. * we have to save it as a separate value.
  316. **/
  317. $FileName = func_get_arg($i);
  318. if (!is_file(CONVERT_TABLES_DIR . $FileName))
  319. {
  320. print $this->DebugOutput(0, 0, CONVERT_TABLES_DIR . $FileName); //Print an error message
  321. exit;
  322. }
  323. $FileWithEncTabe = fopen(CONVERT_TABLES_DIR . $FileName, "r") or die(); //This die(); is just to make sure...
  324. while(!feof($FileWithEncTabe))
  325. {
  326. /**
  327. * We asume that line is not longer
  328. * than 1024 which is the default value for fgets function
  329. **/
  330. if($OneLine=trim(fgets($FileWithEncTabe, 1024)))
  331. {
  332. /**
  333. * We don't need all comment lines. I check only for "#" sign, because
  334. * this is a way of making comments by unicode.org in thair encoding files
  335. * and that's where the files are from :-)
  336. **/
  337. if (substr($OneLine, 0, 1) != "#")
  338. {
  339. /**
  340. * Sometimes inside the charset file the hex walues are separated by
  341. * "space" and sometimes by "tab", the below preg_split can also be used
  342. * to split files where separator is a ",", "\r", "\n" and "\f"
  343. **/
  344. $HexValue = preg_split ("/[\s,]+/", $OneLine, 3); //We need only first 2 values
  345. /**
  346. * Sometimes char is UNDEFINED, or missing so we can't use it for convertion
  347. **/
  348. if (substr($HexValue[1], 0, 1) != "#")
  349. {
  350. $ArrayKey = strtoupper(str_replace(strtolower("0x"), "", $HexValue[1]));
  351. $ArrayValue = strtoupper(str_replace(strtolower("0x"), "", $HexValue[0]));
  352. $ConvertTable[func_get_arg($i)][$ArrayKey] = $ArrayValue;
  353. }
  354. } //if (substr($OneLine,...
  355. } //if($OneLine=trim(f...
  356. } //while(!feof($FirstFileWi...
  357. } //for($i = 0; $i < func_...
  358. /**
  359. * The last thing is to check if by any reason both encoding tables are not the same.
  360. * For example, it will happen when you save the encoding table file with a wrong name
  361. * - of another charset.
  362. **/
  363. if ((func_num_args() > 1) && (count($ConvertTable[$FirstEncoding]) == count($ConvertTable[$SecondEncoding])) && (count(array_diff_assoc($ConvertTable[$FirstEncoding], $ConvertTable[$SecondEncoding])) == 0))
  364. {
  365. print $this->DebugOutput(1, 1, "$FirstEncoding, $SecondEncoding");
  366. }
  367. return $ConvertTable;
  368. }
  369. /**
  370. * ConvertCharset::Convert()
  371. *
  372. * This is a basic function you are using. I hope that you can figure out this function syntax :-)
  373. *
  374. * @param string $StringToChange The string you want to change :)
  375. * @param string $FromCharset Name of $StringToChange encoding, you have to know it.
  376. * @param string $ToCharset Name of a charset you want to get for $StringToChange.
  377. * @param boolean $TurnOnEntities Set to true or 1 if you want to use numeric entities insted of regular chars.
  378. * @return string Converted string in brand new encoding :)
  379. * @version 1.0 2004-07-27 01:09
  380. **/
  381. function Convert ($StringToChange, $FromCharset, $ToCharset, $TurnOnEntities = false)
  382. {
  383. /**
  384. * Check are there all variables
  385. **/
  386. if ($StringToChange == "")
  387. {
  388. print $this->DebugOutput(0, 3, "\$StringToChange");
  389. }
  390. else if ($FromCharset == "")
  391. {
  392. print $this->DebugOutput(0, 3, "\$FromCharset");
  393. }
  394. else if ($ToCharset == "")
  395. {
  396. print $this->DebugOutput(0, 3, "\$ToCharset");
  397. }
  398. /**
  399. * Now a few variables need to be set.
  400. **/
  401. $NewString = "";
  402. $this->Entities = $TurnOnEntities;
  403. /**
  404. * For all people who like to use uppercase for charset encoding names :)
  405. **/
  406. $FromCharset = strtolower($FromCharset);
  407. $ToCharset = strtolower($ToCharset);
  408. /**
  409. * Of course you can make a conversion from one charset to the same one :)
  410. * but I feel obligate to let you know about it.
  411. **/
  412. if ($FromCharset == $ToCharset)
  413. {
  414. print $this->DebugOutput(1, 0, $FromCharset);
  415. }
  416. if (($FromCharset == $ToCharset) AND ($FromCharset == "utf-8"))
  417. {
  418. print $this->DebugOutput(0, 4, $FromCharset);
  419. exit;
  420. }
  421. /**
  422. * This divison was made to prevent errors during convertion to/from utf-8 with
  423. * "entities" enabled, because we need to use proper destination(to)/source(from)
  424. * encoding table to write proper entities.
  425. *
  426. * This is the first case. We are convertinf from 1byte chars...
  427. **/
  428. if ($FromCharset != "utf-8")
  429. {
  430. /**
  431. * Now build table with both charsets for encoding change.
  432. **/
  433. if ($ToCharset != "utf-8")
  434. {
  435. $CharsetTable = $this->MakeConvertTable ($FromCharset, $ToCharset);
  436. }
  437. else
  438. {
  439. $CharsetTable = $this->MakeConvertTable ($FromCharset);
  440. }
  441. /**
  442. * For each char in a string...
  443. **/
  444. for ($i = 0; $i < strlen($StringToChange); $i++)
  445. {
  446. $HexChar = "";
  447. $UnicodeHexChar = "";
  448. $HexChar = strtoupper(dechex(ord($StringToChange[$i])));
  449. // This is fix from Mario Klingemann, it prevents
  450. // droping chars below 16 because of missing leading 0 [zeros]
  451. if (strlen($HexChar)==1) $HexChar = "0".$HexChar;
  452. //end of fix by Mario Klingemann
  453. // This is quick fix of 10 chars in gsm0338
  454. // Thanks goes to Andrea Carpani who pointed on this problem
  455. // and solve it ;)
  456. if (($FromCharset == "gsm0338") && ($HexChar == '1B')) {
  457. $i++;
  458. $HexChar .= strtoupper(dechex(ord($StringToChange[$i])));
  459. }
  460. // end of workarround on 10 chars from gsm0338
  461. if ($ToCharset != "utf-8")
  462. {
  463. if (in_array($HexChar, $CharsetTable[$FromCharset]))
  464. {
  465. $UnicodeHexChar = array_search($HexChar, $CharsetTable[$FromCharset]);
  466. $UnicodeHexChars = explode("+",$UnicodeHexChar);
  467. for($UnicodeHexCharElement = 0; $UnicodeHexCharElement < count($UnicodeHexChars); $UnicodeHexCharElement++)
  468. {
  469. if (array_key_exists($UnicodeHexChars[$UnicodeHexCharElement], $CharsetTable[$ToCharset]))
  470. {
  471. if ($this->Entities == true)
  472. {
  473. $NewString .= $this->UnicodeEntity($this->HexToUtf($UnicodeHexChars[$UnicodeHexCharElement]));
  474. }
  475. else
  476. {
  477. $NewString .= chr(hexdec($CharsetTable[$ToCharset][$UnicodeHexChars[$UnicodeHexCharElement]]));
  478. }
  479. }
  480. else
  481. {
  482. print $this->DebugOutput(0, 1, $StringToChange[$i]);
  483. }
  484. } //for($UnicodeH...
  485. }
  486. else
  487. {
  488. print $this->DebugOutput(0, 2,$StringToChange[$i]);
  489. }
  490. }
  491. else
  492. {
  493. if (in_array("$HexChar", $CharsetTable[$FromCharset]))
  494. {
  495. $UnicodeHexChar = array_search($HexChar, $CharsetTable[$FromCharset]);
  496. /**
  497. * Sometimes there are two or more utf-8 chars per one regular char.
  498. * Extream, example is polish old Mazovia encoding, where one char contains
  499. * two lettes 007a (z) and 0142 (l slash), we need to figure out how to
  500. * solve this problem.
  501. * The letters are merge with "plus" sign, there can be more than two chars.
  502. * In Mazowia we have 007A+0142, but sometimes it can look like this
  503. * 0x007A+0x0142+0x2034 (that string means nothing, it just shows the possibility...)
  504. **/
  505. $UnicodeHexChars = explode("+",$UnicodeHexChar);
  506. for($UnicodeHexCharElement = 0; $UnicodeHexCharElement < count($UnicodeHexChars); $UnicodeHexCharElement++)
  507. {
  508. if ($this->Entities == true)
  509. {
  510. $NewString .= $this->UnicodeEntity($this->HexToUtf($UnicodeHexChars[$UnicodeHexCharElement]));
  511. }
  512. else
  513. {
  514. $NewString .= $this->HexToUtf($UnicodeHexChars[$UnicodeHexCharElement]);
  515. }
  516. } // for
  517. }
  518. else
  519. {
  520. print $this->DebugOutput(0, 2, $StringToChange[$i]);
  521. }
  522. }
  523. }
  524. }
  525. /**
  526. * This is second case. We are encoding from multibyte char string.
  527. **/
  528. else if($FromCharset == "utf-8")
  529. {
  530. $HexChar = "";
  531. $UnicodeHexChar = "";
  532. $CharsetTable = $this->MakeConvertTable ($ToCharset);
  533. foreach ($CharsetTable[$ToCharset] as $UnicodeHexChar => $HexChar)
  534. {
  535. if ($this->Entities == true) {
  536. $EntitieOrChar = $this->UnicodeEntity($this->HexToUtf($UnicodeHexChar));
  537. }
  538. else
  539. {
  540. $EntitieOrChar = chr(hexdec($HexChar));
  541. }
  542. $StringToChange = str_replace($this->HexToUtf($UnicodeHexChar), $EntitieOrChar, $StringToChange);
  543. }
  544. $NewString = $StringToChange;
  545. }
  546. return $NewString;
  547. }
  548. /**
  549. * ConvertCharset::DebugOutput()
  550. *
  551. * This function is not really necessary, the debug output could stay inside of
  552. * source code but like this, it's easier to manage and translate.
  553. * Besides I couldn't find good coment/debug class :-) Maybe I'll write one someday...
  554. *
  555. * All messages depend on DEBUG_MODE level, as I was writing before you can set this value to:
  556. * - -1 - No errors or notces are shown
  557. * - 0 - Only error messages are shown, no notices
  558. * - 1 - Error messages and notices are shown
  559. *
  560. * @param int $Group Message groupe: error - 0, notice - 1
  561. * @param int $Number Following message number
  562. * @param mix $Value This walue is whatever you want, usualy it's some parameter value, for better message understanding.
  563. * @return string String with a proper message.
  564. **/
  565. function DebugOutput ($Group, $Number, $Value = false)
  566. {
  567. //$Debug [$Group][$Number] = "Message, can by with $Value";
  568. //$Group[0] - Errors
  569. //$Group[1] - Notice
  570. $Debug[0][0] = "Error, can NOT read file: " . $Value . "<br>";
  571. $Debug[0][1] = "Error, can't find maching char \"". $Value ."\" in destination encoding table!" . "<br>";
  572. $Debug[0][2] = "Error, can't find maching char \"". $Value ."\" in source encoding table!" . "<br>";
  573. $Debug[0][3] = "Error, you did NOT set variable " . $Value . " in Convert() function." . "<br>";
  574. $Debug[0][4] = "You can NOT convert string from " . $Value . " to " . $Value . "!" . "<BR>";
  575. $Debug[1][0] = "Notice, you are trying to convert string from ". $Value ." to ". $Value .", don't you feel it's strange? ;-)" . "<br>";
  576. $Debug[1][1] = "Notice, both charsets " . $Value . " are identical! Check encoding tables files." . "<br>";
  577. $Debug[1][2] = "Notice, there is no unicode char in the string you are trying to convert." . "<br>";
  578. if (DEBUG_MODE >= $Group)
  579. {
  580. return $Debug[$Group][$Number];
  581. }
  582. } // function DebugOutput
  583. } //class ends here
  584. ?>