再谈nfo文件
一般的nfo文件是cp437编码的, 而一般的ttf字体是用unicode编码索引的,所以只要将cp437的nfo文件转为unicode编码,直接查看时就不会有乱码了。之前提到的字符映射表也是这个道理,只不过我们有现成的iconv库就更方便了,只需要iconv(‘CP437′, ‘UTF-8′, $str)就可以了。
顺便总结一下各种显示形式的实现方式:
nfo2txt
将cp437编码转为unicode编码即可, php中用iconv(‘CP437′, ‘UTF-8′, $str), 如果没有现成的库,可以用字符映射表来做,这是我之前仿写的一个c程序,可以在这里下载,下载后把nfo文件关联到此程序,会自动在同目录下成一个同名的txt文件,可以用记事本查看。源代码在下面,仅供参考。
nfo2pic
1. 利用nfo2txt的方式,转码后用gd中的imagettftext将内容写到画板上。参看示例代码2。
2. 制作gd专用字体,用imageloadfont直接绘制nfo内容,参考我以前写的文章和示例代码3。
当然还有其它方式,相比起来麻烦一点,在这里就不说了。
nfo2html
也是利用nfo2txt的方式,将cp437编码转为unicode之后,将那些非ascii字符转为unicode字符引用。ie7和firefox等浏览器就可以显示了,ie6还需要制作eot字体才可以,具体参考以前的文章。
示例代码1:
- <?php
- $nfo = file_get_contents("zwt.nfo");
- $nfo = iconv('CP437', 'UTF-8', $nfo);
- file_put_contents("zwt.txt", $nfo);
- ?>
示例代码2:
- <?php
- header("Content-type: image/png");
- $lines = file('zwt.nfo');
- $im = imagecreatetruecolor(700, count($lines) * 16);
- $white = imagecolorallocate($im, 255, 255, 255);
- $black = imagecolorallocate($im, 0, 0, 0);
- $font = 'cour.ttf';
- $lines = file('zwt.nfo');
- foreach ($lines as $i => $line)
- {
- $line = iconv('CP437', 'UTF-8', $line);
- imagettftext($im, 10, 0, 0, $i * 16, $white, $font, $line);
- }
- imagepng($im);
- imagedestroy($im);
- ?>
nfo2txt源代码(c):
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #define LINEWIDTH 80
- void nfo2txt(char *, char *);
- wchar_t conv_table[] = {
- /* 0*/ 0x0000, 0x263a, 0x263b, 0x2665, 0x2666,
- /* 5*/ 0x2663, 0x2660, 0x2022, 0x25d8, 0x0000,
- /* 10*/ 0x0000, 0x2642, 0x2640, 0x0000, 0x266b,
- /* 15*/ 0x263c, 0x25ba, 0x25c4, 0x2195, 0x203c,
- /* 20*/ 0x00b6, 0x00a7, 0x25ac, 0x21a8, 0x2191,
- /* 25*/ 0x2193, 0x2192, 0x2190, 0x221f, 0x2194,
- /* 30*/ 0x25b2, 0x25bc, 0x0000, 0x0000, 0x0022,
- /* 35*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0027,
- /* 40*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- /* 45*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- /* 50*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- /* 55*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- /* 60*/ 0x003c, 0x0000, 0x0000, 0x0000, 0x0000,
- /* 65*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- /* 70*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- /* 75*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- /* 80*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- /* 85*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- /* 90*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- /* 95*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- /*100*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- /*105*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- /*110*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- /*115*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- /*120*/ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- /*125*/ 0x0000, 0x0000, 0x2302, 0x00c7, 0x00fc,
- /*130*/ 0x00e9, 0x00e2, 0x00e4, 0x00e0, 0x00e5,
- /*135*/ 0x00e7, 0x00ea, 0x00eb, 0x00e8, 0x00ef,
- /*140*/ 0x00ee, 0x00ec, 0x00c4, 0x00c5, 0x00c9,
- /*145*/ 0x00e6, 0x00c6, 0x00f4, 0x00f6, 0x00f2,
- /*150*/ 0x00fb, 0x00f9, 0x00ff, 0x00d6, 0x00dc,
- /*155*/ 0x00a2, 0x00a3, 0x00a5, 0x20a7, 0x0192,
- /*160*/ 0x00e1, 0x00ed, 0x00f3, 0x00fa, 0x00f1,
- /*165*/ 0x00d1, 0x00aa, 0x00ba, 0x00bf, 0x2310,
- /*170*/ 0x00ac, 0x00bd, 0x00bc, 0x00a1, 0x00ab,
- /*175*/ 0x00bb, 0x2591, 0x2592, 0x2593, 0x2502,
- /*180*/ 0x2524, 0x2561, 0x2562, 0x2556, 0x2555,
- /*185*/ 0x2563, 0x2551, 0x2557, 0x255d, 0x255c,
- /*190*/ 0x255b, 0x2510, 0x2514, 0x2534, 0x252c,
- /*195*/ 0x251c, 0x2500, 0x253c, 0x255e, 0x255f,
- /*200*/ 0x255a, 0x2554, 0x2569, 0x2566, 0x2560,
- /*205*/ 0x2550, 0x256c, 0x2567, 0x2568, 0x2564,
- /*210*/ 0x2565, 0x2559, 0x2558, 0x2552, 0x2553,
- /*215*/ 0x256b, 0x256a, 0x2518, 0x250c, 0x2588,
- /*220*/ 0x2584, 0x258c, 0x2590, 0x2580, 0x03b1,
- /*225*/ 0x03b2, 0x0393, 0x03c0, 0x03a3, 0x03c3,
- /*230*/ 0x03bc, 0x03c4, 0x03a6, 0x03b8, 0x2126,
- /*235*/ 0x03b4, 0x221e, 0x00f8, 0x03b5, 0x2229,
- /*240*/ 0x2261, 0x00b1, 0x2265, 0x2264, 0x2320,
- /*245*/ 0x2321, 0x00f7, 0x2248, 0x00b0, 0x00b7,
- /*250*/ 0x02d9, 0x221a, 0x207f, 0x00b2, 0x25a0,
- /*255*/ 0x00a0
- };
- int main(int argc, char *argv[])
- {
- char filename[100];
- char output[100];
- if (argc == 1 || argc > 3)
- {
- printf("usage: %s <filename> [output]\n", *argv);
- return -1;
- }
- strcpy(filename, argv[1]);
- if (!argv[2])
- strcpy(output, strcat(argv[1], ".txt"));
- else
- strcpy(output, argv[2]);
- nfo2txt(filename, output);
- return 0;
- }
- void nfo2txt(char *filename, char *output)
- {
- FILE *fp_in, *fp_out;
- unsigned int c;
- wchar_t u;
- wchar_t *p = conv_table;
- fp_in = fopen(filename, "r");
- if (!fp_in)
- {
- printf("error: can not open file: %s\n", filename);
- return;
- }
- if (output)
- {
- fp_out = fopen(output, "wb");
- fputwc(0xfeff, fp_out);
- }
- else
- fp_out = stdout;
- while ((c = getc(fp_in)) != EOF)
- {
- if (*(p + c) != 0)
- u = *(p + c);
- else
- {
- if (c == '\n')
- fputwc('\r', fp_out);
- u = c;
- }
- fputwc(u, fp_out);
- }
- fclose(fp_in);
- if (output)
- {
- fclose(fp_out);
- printf("saved as %s\n", output);
- }
- }
在在 said,
February 6, 2008 @ 11:00 am
到访
欢迎光临听景777-属于个人的Blog
访问地址 http://www.boynan.com/2.htm
联系邮件:tingjing777@gmail.com
macleo said,
September 18, 2008 @ 2:38 pm
呵呵….见过nfo文件….呵呵…一直认为是hacker的说明文件….
牛….
oschina said,
December 15, 2008 @ 7:43 am
very good , welcome to http://www.oschina.net
cp437 said,
August 19, 2009 @ 2:53 pm
@color 0c
@chcp 437 > nul
@type %1
@echo.
@echo.
@echo.
@pause
叶沙杯江 said,
December 8, 2013 @ 11:10 am
杭州最好的夜场是杭州东方魅力www.dongfangmeili.cn
杭州最好的ktv是哪儿?是杭州东方魅力www.dongfangmeili.cn
杭州夜场招聘首选杭州东方魅力www.dongfangmeili.com.cn
杭州最好的夜总会是杭州东方魅力www.dongfangmeili.com.cn
杭州东方魅力官方网站欢迎你 联系电话:13666653761 官方微信:dongfangmeili