fork(2) download
  1. <?php
  2. //Author: parfait.team@gmail.com
  3. function utf8ToUnicode($str){
  4. //split word
  5. preg_match_all('/./u',$str,$matches);
  6.  
  7. $c = "";
  8. foreach($matches[0] as $m){
  9. $c .= "&#".base_convert(bin2hex(iconv('UTF-8',"UCS-4",$m)),16,10);
  10. }
  11. return $c;
  12. }
  13. function unicodeToUtf8($unicode_str){
  14. $intArr = explode("&#", $unicode_str);
  15. $retr = "";
  16. foreach($intArr as $cval)
  17. {
  18. if(!empty($cval))
  19. $retr .= unicodeCharToUtf8($cval);
  20. }
  21. return $retr;
  22. }
  23. function unicodeCharToUtf8($unicode_c){
  24. $unicode_c_val = intval($unicode_c);
  25. $f=0x80; // 10000000
  26. $str = "";
  27. // U-00000000 - U-0000007F: 0xxxxxxx
  28. if($unicode_c_val <= 0x7F)
  29. {
  30. $str = chr($unicode_c_val);
  31. }
  32. //U-00000080 - U-000007FF: 110xxxxx 10xxxxxx
  33. else if($unicode_c_val >= 0x80 && $unicode_c_val <= 0x7FF)
  34. {
  35. $h=0xC0; // 11000000
  36. $c1 = $unicode_c_val >> 6 | $h;
  37. $c2 = ($unicode_c_val & 0x3F) | $f;
  38. $str = chr($c1).chr($c2);
  39. }
  40. //U-00000800 - U-0000FFFF: 1110xxxx 10xxxxxx 10xxxxxx
  41. else if($unicode_c_val >= 0x800 && $unicode_c_val <= 0xFFFF)
  42. {
  43. $h=0xE0; // 11100000
  44. $c1 = $unicode_c_val >> 12 | $h;
  45. $c2 = (($unicode_c_val & 0xFC0) >> 6) | $f;
  46. $c3 = ($unicode_c_val & 0x3F) | $f;
  47. $str=chr($c1).chr($c2).chr($c3);
  48. }
  49. //U-00010000 - U-001FFFFF: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
  50. else if($unicode_c_val >= 0x10000 && $unicode_c_val <= 0x1FFFFF)
  51. {
  52. $h=0xF0; // 11110000
  53. $c1 = $unicode_c_val >> 18 | $h;
  54. $c2 = (($unicode_c_val & 0x3F000) >>12) | $f;
  55. $c3 = (($unicode_c_val & 0xFC0) >>6) | $f;
  56. $c4 = ($unicode_c_val & 0x3F) | $f;
  57. $str = chr($c1).chr($c2).chr($c3).chr($c4);
  58. }
  59. //U-00200000 - U-03FFFFFF: 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
  60. else if($unicode_c_val >= 0x200000 && $unicode_c_val <= 0x3FFFFFF)
  61. {
  62. $h=0xF8; // 11111000
  63. $c1 = $unicode_c_val >> 24 | $h;
  64. $c2 = (($unicode_c_val & 0xFC0000)>>18) | $f;
  65. $c3 = (($unicode_c_val & 0x3F000) >>12) | $f;
  66. $c4 = (($unicode_c_val & 0xFC0) >>6) | $f;
  67. $c5 = ($unicode_c_val & 0x3F) | $f;
  68. $str = chr($c1).chr($c2).chr($c3).chr($c4).chr($c5);
  69. }
  70. //U-04000000 - U-7FFFFFFF: 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
  71. else if($unicode_c_val >= 0x4000000 && $unicode_c_val <= 0x7FFFFFFF)
  72. {
  73. $h=0xFC; // 11111100
  74. $c1 = $unicode_c_val >> 30 | $h;
  75. $c2 = (($unicode_c_val & 0x3F000000)>>24) | $f;
  76. $c3 = (($unicode_c_val & 0xFC0000)>>18) | $f;
  77. $c4 = (($unicode_c_val & 0x3F000) >>12) | $f;
  78. $c5 = (($unicode_c_val & 0xFC0) >>6) | $f;
  79. $c6 = ($unicode_c_val & 0x3F) | $f;
  80. $str = chr($c1).chr($c2).chr($c3).chr($c4).chr($c5).chr($c6);
  81. }
  82.  
  83. return $str;
  84. }
  85.  
  86. //Print result
  87. $raw_str = "
  88. 雨傘運動或稱雨傘革命、遮打運動、遮打革命(英語:Umbrella Movement 或 Umbrella Revolution)是於2014年9月26日起在香港為爭取真普選而發起的一系列公民抗命,逾60-70萬(人次)香港市民佔據多個主要商業區靜坐及示威,地點包括金鐘、中環、灣仔、銅鑼灣、旺角和尖沙咀,旨在要求包括撤回中國全國人大常委會(人大常委)所確定之2017年行政長官選舉及2016年立法會選舉框架和候選人提名方案,爭取行政長官選舉的公民提名權及取消立法會功能界別等訴求。
  89.  
  90. The 2014 Hong Kong protests, also known as the Umbrella Movement or Umbrella Revolution, began in September 2014 when activists in Hong Kong protested outside the HKSAR government headquarters and occupied several major city intersections after China's Standing Committee of the National People's Congress (NPCSC) announced its decision on proposed electoral reform.[7] In disallowing civil nominations, the NPCSC made it clear that a 1200-member nominating committee, which would remain nominated by the business factions, would elect two to three electoral candidates with more than half of the votes before the general public could vote on them
  91. ";
  92. $unicode_str = utf8ToUnicode($raw_str);
  93. $utf8_str = unicodeToUtf8($unicode_str);
  94.  
  95. ?>
  96. <html>
  97. <head>
  98. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  99. </head>
  100. <body>
  101. <b>Raw text:</b><br/>
  102. <?=$raw_str?><br/><br/>
  103. <b>UTF8 to Unicode:</b><br/>
  104. <?=$unicode_str?><br/><br/>
  105. <b>Unicode to UTF8:</b><br/>
  106. <?=$utf8_str?>
  107. </body>
  108. </html>
Success #stdin #stdout 0.01s 20552KB
stdin
Standard input is empty
stdout
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">	
	</head>
	<body>
		<b>Raw text:</b><br/>
		
雨傘運動或稱雨傘革命、遮打運動、遮打革命(英語:Umbrella Movement 或 Umbrella Revolution)是於2014年9月26日起在香港為爭取真普選而發起的一系列公民抗命,逾60-70萬(人次)香港市民佔據多個主要商業區靜坐及示威,地點包括金鐘、中環、灣仔、銅鑼灣、旺角和尖沙咀,旨在要求包括撤回中國全國人大常委會(人大常委)所確定之2017年行政長官選舉及2016年立法會選舉框架和候選人提名方案,爭取行政長官選舉的公民提名權及取消立法會功能界別等訴求。

The 2014 Hong Kong protests, also known as the Umbrella Movement or Umbrella Revolution, began in September 2014 when activists in Hong Kong protested outside the HKSAR government headquarters and occupied several major city intersections after China's Standing Committee of the National People's Congress (NPCSC) announced its decision on proposed electoral reform.[7] In disallowing civil nominations, the NPCSC made it clear that a 1200-member nominating committee, which would remain nominated by the business factions, would elect two to three electoral candidates with more than half of the votes before the general public could vote on them
<br/><br/>
		<b>UTF8 to Unicode:</b><br/>
		&#38632&#20632&#36939&#21205&#25110&#31281&#38632&#20632&#38761&#21629&#12289&#36974&#25171&#36939&#21205&#12289&#36974&#25171&#38761&#21629&#65288&#33521&#35486&#65306&#85&#109&#98&#114&#101&#108&#108&#97&#32&#77&#111&#118&#101&#109&#101&#110&#116&#32&#25110&#32&#85&#109&#98&#114&#101&#108&#108&#97&#32&#82&#101&#118&#111&#108&#117&#116&#105&#111&#110&#65289&#26159&#26044&#50&#48&#49&#52&#24180&#57&#26376&#50&#54&#26085&#36215&#22312&#39321&#28207&#28858&#29229&#21462&#30495&#26222&#36984&#32780&#30332&#36215&#30340&#19968&#31995&#21015&#20844&#27665&#25239&#21629&#65292&#36926&#54&#48&#45&#55&#48&#33836&#65288&#20154&#27425&#65289&#39321&#28207&#24066&#27665&#20308&#25818&#22810&#20491&#20027&#35201&#21830&#26989&#21312&#38748&#22352&#21450&#31034&#23041&#65292&#22320&#40670&#21253&#25324&#37329&#37912&#12289&#20013&#29872&#12289&#28771&#20180&#12289&#37509&#38012&#28771&#12289&#26106&#35282&#21644&#23574&#27801&#21632&#65292&#26088&#22312&#35201&#27714&#21253&#25324&#25764&#22238&#20013&#22283&#20840&#22283&#20154&#22823&#24120&#22996&#26371&#65288&#20154&#22823&#24120&#22996&#65289&#25152&#30906&#23450&#20043&#50&#48&#49&#55&#24180&#34892&#25919&#38263&#23448&#36984&#33289&#21450&#50&#48&#49&#54&#24180&#31435&#27861&#26371&#36984&#33289&#26694&#26550&#21644&#20505&#36984&#20154&#25552&#21517&#26041&#26696&#65292&#29229&#21462&#34892&#25919&#38263&#23448&#36984&#33289&#30340&#20844&#27665&#25552&#21517&#27402&#21450&#21462&#28040&#31435&#27861&#26371&#21151&#33021&#30028&#21029&#31561&#35380&#27714&#12290&#84&#104&#101&#32&#50&#48&#49&#52&#32&#72&#111&#110&#103&#32&#75&#111&#110&#103&#32&#112&#114&#111&#116&#101&#115&#116&#115&#44&#32&#97&#108&#115&#111&#32&#107&#110&#111&#119&#110&#32&#97&#115&#32&#116&#104&#101&#32&#85&#109&#98&#114&#101&#108&#108&#97&#32&#77&#111&#118&#101&#109&#101&#110&#116&#32&#111&#114&#32&#85&#109&#98&#114&#101&#108&#108&#97&#32&#82&#101&#118&#111&#108&#117&#116&#105&#111&#110&#44&#32&#98&#101&#103&#97&#110&#32&#105&#110&#32&#83&#101&#112&#116&#101&#109&#98&#101&#114&#32&#50&#48&#49&#52&#32&#119&#104&#101&#110&#32&#97&#99&#116&#105&#118&#105&#115&#116&#115&#32&#105&#110&#32&#72&#111&#110&#103&#32&#75&#111&#110&#103&#32&#112&#114&#111&#116&#101&#115&#116&#101&#100&#32&#111&#117&#116&#115&#105&#100&#101&#32&#116&#104&#101&#32&#72&#75&#83&#65&#82&#32&#103&#111&#118&#101&#114&#110&#109&#101&#110&#116&#32&#104&#101&#97&#100&#113&#117&#97&#114&#116&#101&#114&#115&#32&#97&#110&#100&#32&#111&#99&#99&#117&#112&#105&#101&#100&#32&#115&#101&#118&#101&#114&#97&#108&#32&#109&#97&#106&#111&#114&#32&#99&#105&#116&#121&#32&#105&#110&#116&#101&#114&#115&#101&#99&#116&#105&#111&#110&#115&#32&#97&#102&#116&#101&#114&#32&#67&#104&#105&#110&#97&#39&#115&#32&#83&#116&#97&#110&#100&#105&#110&#103&#32&#67&#111&#109&#109&#105&#116&#116&#101&#101&#32&#111&#102&#32&#116&#104&#101&#32&#78&#97&#116&#105&#111&#110&#97&#108&#32&#80&#101&#111&#112&#108&#101&#39&#115&#32&#67&#111&#110&#103&#114&#101&#115&#115&#32&#40&#78&#80&#67&#83&#67&#41&#32&#97&#110&#110&#111&#117&#110&#99&#101&#100&#32&#105&#116&#115&#32&#100&#101&#99&#105&#115&#105&#111&#110&#32&#111&#110&#32&#112&#114&#111&#112&#111&#115&#101&#100&#32&#101&#108&#101&#99&#116&#111&#114&#97&#108&#32&#114&#101&#102&#111&#114&#109&#46&#91&#55&#93&#32&#73&#110&#32&#100&#105&#115&#97&#108&#108&#111&#119&#105&#110&#103&#32&#99&#105&#118&#105&#108&#32&#110&#111&#109&#105&#110&#97&#116&#105&#111&#110&#115&#44&#32&#116&#104&#101&#32&#78&#80&#67&#83&#67&#32&#109&#97&#100&#101&#32&#105&#116&#32&#99&#108&#101&#97&#114&#32&#116&#104&#97&#116&#32&#97&#32&#49&#50&#48&#48&#45&#109&#101&#109&#98&#101&#114&#32&#110&#111&#109&#105&#110&#97&#116&#105&#110&#103&#32&#99&#111&#109&#109&#105&#116&#116&#101&#101&#44&#32&#119&#104&#105&#99&#104&#32&#119&#111&#117&#108&#100&#32&#114&#101&#109&#97&#105&#110&#32&#110&#111&#109&#105&#110&#97&#116&#101&#100&#32&#98&#121&#32&#116&#104&#101&#32&#98&#117&#115&#105&#110&#101&#115&#115&#32&#102&#97&#99&#116&#105&#111&#110&#115&#44&#32&#119&#111&#117&#108&#100&#32&#101&#108&#101&#99&#116&#32&#116&#119&#111&#32&#116&#111&#32&#116&#104&#114&#101&#101&#32&#101&#108&#101&#99&#116&#111&#114&#97&#108&#32&#99&#97&#110&#100&#105&#100&#97&#116&#101&#115&#32&#119&#105&#116&#104&#32&#109&#111&#114&#101&#32&#116&#104&#97&#110&#32&#104&#97&#108&#102&#32&#111&#102&#32&#116&#104&#101&#32&#118&#111&#116&#101&#115&#32&#98&#101&#102&#111&#114&#101&#32&#116&#104&#101&#32&#103&#101&#110&#101&#114&#97&#108&#32&#112&#117&#98&#108&#105&#99&#32&#99&#111&#117&#108&#100&#32&#118&#111&#116&#101&#32&#111&#110&#32&#116&#104&#101&#109<br/><br/>
		<b>Unicode to UTF8:</b><br/>
		雨傘運動或稱雨傘革命、遮打運動、遮打革命(英語:Umbrella Movement 或 Umbrella Revolution)是於2014年9月26日起在香港為爭取真普選而發起的一系列公民抗命,逾60-70萬(人次)香港市民佔據多個主要商業區靜坐及示威,地點包括金鐘、中環、灣仔、銅鑼灣、旺角和尖沙咀,旨在要求包括撤回中國全國人大常委會(人大常委)所確定之2017年行政長官選舉及2016年立法會選舉框架和候選人提名方案,爭取行政長官選舉的公民提名權及取消立法會功能界別等訴求。The 2014 Hong Kong protests, also known as the Umbrella Movement or Umbrella Revolution, began in September 2014 when activists in Hong Kong protested outside the HKSAR government headquarters and occupied several major city intersections after China's Standing Committee of the National People's Congress (NPCSC) announced its decision on proposed electoral reform.[7] In disallowing civil nominations, the NPCSC made it clear that a 1200-member nominating committee, which would remain nominated by the business factions, would elect two to three electoral candidates with more than half of the votes before the general public could vote on them	</body>
</html>