NFO2TXT

由於nfo文件的特殊性,需要特殊的字體或編碼才能夠正常顯示。如果你用計事本查看,ascii碼大於127的字符是亂碼一堆。有沒有辦法用記事本來查看nfo呢?
看到ibic原創的nfo2txt (C語言版),我根據他的映射表做了這個php小程序。將nfo轉換成unicode文本文件,外觀基本一樣。

需要設置一下記事本的字體爲courier new或其他等寬字體才能正常查看。
演示: http://0day.ugia.net/program/nfo2pic/nfo2txt.php

  1. <?php
  2. /**
  3. * NFO TO TEXT (php version)
  4. *
  5. * Special thanks to ibic@9down
  6. * @author legend([email protected])
  7. */ 
  8.  
  9. $conv_table = array(
  10. /*  0*/ 0x263a, 0x263b, 0x2665, 0x2666, 0x2663,
  11. /*  5*/ 0x2660, 0x25cf, 0x25d8, 0x2642, 0x2640,
  12. /* 10*/ 0x0000, 0x263c, 0x25ba, 0x0000, 0x2195,
  13. /* 15*/ 0x203c, 0x00b6, 0x00a7, 0x00f5, 0x21a8,
  14. /* 20*/ 0x2191, 0x2193, 0x2192, 0x2190, 0x221f,
  15. /* 25*/ 0x2194, 0x25b2, 0x25bc, 0x0000, 0x0000,
  16. /* 30*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  17. /* 35*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  18. /* 40*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  19. /* 45*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  20. /* 50*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  21. /* 55*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  22. /* 60*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  23. /* 65*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  24. /* 70*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  25. /* 75*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  26. /* 80*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  27. /* 85*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  28. /* 90*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  29. /* 95*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  30. /*100*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  31. /*105*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  32. /*110*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  33. /*115*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  34. /*120*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  35. /*125*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  36. /*130*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  37. /*135*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  38. /*140*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  39. /*145*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  40. /*150*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  41. /*155*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  42. /*160*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  43. /*165*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  44. /*170*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  45. /*175*/ 0x0000, 0x2591, 0x2592, 0x2593, 0x2502,
  46. /*180*/ 0x2524, 0x2561, 0x2562, 0x2556, 0x2555,
  47. /*185*/ 0x2563, 0x2551, 0x2557, 0x255d, 0x255c,
  48. /*190*/ 0x255b, 0x2510, 0x2514, 0x2534, 0x252c,
  49. /*195*/ 0x251c, 0x2500, 0x253c, 0x255e, 0x255f,
  50. /*200*/ 0x255a, 0x2554, 0x2569, 0x2566, 0x2560,
  51. /*205*/ 0x2550, 0x256c, 0x2567, 0x2568, 0x2564,
  52. /*210*/ 0x2565, 0x2559, 0x2558, 0x2552, 0x2553,
  53. /*215*/ 0x256a, 0x256a, 0x2518, 0x250c, 0x2588,
  54. /*220*/ 0x2584, 0x258c, 0x2590, 0x2580, 0x03b1,
  55. /*225*/ 0x03b2, 0x0000, 0x0000, 0x0000, 0x0000,
  56. /*230*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  57. /*235*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  58. /*240*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  59. /*245*/ 0x0000, 0x0000, 0x0000, 0x25cb, 0x2014,
  60. /*250*/ 0x2013, 0x0000, 0x0000, 0x0000, 0x25a0,
  61. /*255*/ 0x0000,
  62. );
  63. if(is_uploaded_file($_FILES['filename']['tmp_name']))
  64. {
  65.     $fname = $_FILES['filename']['name'].".txt";
  66.     $str   = file_get_contents($_FILES['filename']['tmp_name']);
  67.     $txt   = conv_nfo($str);
  68.     header('Content-type: application/x-octet-stream');
  69.     header('Content-disposition: attachment; filename=' . $fname);
  70.     print $txt;
  71. }
  72. else
  73. {
  74.     echo "<html><head><style type='text/css'>body,input{font-size:11px;font-family:tahoma}</style></head><body>";
  75.     echo "<form action='' method='post' enctype='multipart/form-data'>/n";
  76.     echo "<input type='file' name='filename' size='50′ />";
  77.     echo "<input type='submit' value='GET TXT' />";
  78.     echo "</form>";
  79.     echo "</body>";
  80. }
  81. //cove str
  82. function conv_nfo($str)
  83. {
  84.     global $conv_table;
  85.     for($i = 0; $i < strlen($str); $i ++)
  86.     {
  87.         if($conv_table[ord($str[$i])] == 0)
  88.         {
  89.             $output .= code2utf(ord($str[$i]));
  90.         }
  91.         else
  92.         {
  93.             $output .= code2utf($conv_table[ord($str[$i])]);
  94.         }
  95.     } 
  96.  
  97.     return $output;
  98. }
  99. //code 2 unicode
  100. function code2utf($num)
  101. {
  102.     if($num<128)
  103.         return chr($num);
  104.     if($num<1024)
  105.         return chr(($num>>6)+192).chr(($num&63)+128);
  106.     if($num<32768)
  107.         return chr(($num>>12)+224).chr((($num>>6)&63)+128).chr(($num&63)+128);
  108.     if($num<2097152)
  109.         return chr($num>>18+240).chr((($num>>12)&63)+128).chr(($num>>6)&63+128). chr($num&63+128);
  110.     return '';
  111. }
  112. ?>


效果:
轉載 上傳了這個圖片附件:
.png 22.6 kb,已被瀏覽 5 次


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章