在浏览器中以文本方式显示nfo文件:nfo2html

更新:在线制作eot字体:http://www.ugia.cn/nfo/eot.php

更新:因为以前的映射表不全而且有错误,andot从新做了影射表。现在使用压缩过的courier new字体做嵌入式字体,因为Lucida ConsoleP字体字符不全。nfo2html函数也优化了下,基本没有什么问题了。感谢andot的努力。

感谢nfo在我前面的一篇文章《在浏览器中以文本方式显示nfo文件的完美解决方案》对字符编码的建议,当时没有考虑网页编码的问题,所以这个方法在实际应用中会有些困难。因为在IE中必须指定网页编码为iso8859-1、firefox等其他浏览器中必须为utf-8编码才能正常浏览,当整合进现有的网站中时,会因为网页编码不相同导致乱码。解决这个问题的方法就是把nfo中的字符全部转化为十进制表示的html实体(NCR : Numeric character reference),这样不管网页编码是什么,都会正常显示了。

andot同学重新写了一个nfo2html来代替原先的nfo2txt,ie中还是使用eot字体,已经不需要特殊的字体了,courier new就可以,具体制作方法请参考我前面的那篇文章,firefox、netscape下通过字符映射表转化特殊字符,并把所有字符用十进制的html实体来表示。demo

wp插件显示效果如下:
nfo2html

完整代码(含wordpress插件)下载:nfo2html_and_wpplugin.rar


nfo2html代码片断:

<?php
/**
* NFO TO HTML
*
* Special thanks to ibic@9down
* @author: andot(andot@ujn.edu.cn) & legend(legendsky@hotmail.com)
* @link: http://www.ugia.cn/?p=55, http://www.ugia.cn/?p=49
* @description: convert .nfo file to html
* @version: 2.0
*/
/*  Copyright 2005  andot & legend  (email : andot@ujn.edu.cn & legendsky@hotmail.com)

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
$conv_table = array(
    
/*  0*/ 0x00000x263a0x263b0x26650x2666,
    
/*  5*/ 0x26630x26600x20220x25d80x0000,
    
/* 10*/ 0x00000x26420x26400x00000x266b,
    
/* 15*/ 0x263c0x25ba0x25c40x21950x203c,
    
/* 20*/ 0x00b60x00a70x25ac0x21a80x2191,
    
/* 25*/ 0x21930x21920x21900x221f0x2194,
    
/* 30*/ 0x25b20x25bc0x00000x00000x0022,
    
/* 35*/ 0x00000x00000x00000x00000x0027,
    
/* 40*/ 0x00000x00000x00000x00000x0000,
    
/* 45*/ 0x00000x00000x00000x00000x0000,
    
/* 50*/ 0x00000x00000x00000x00000x0000,
    
/* 55*/ 0x00000x00000x00000x00000x0000,
    
/* 60*/ 0x003c0x00000x00000x00000x0000,
    
/* 65*/ 0x00000x00000x00000x00000x0000,
    
/* 70*/ 0x00000x00000x00000x00000x0000,
    
/* 75*/ 0x00000x00000x00000x00000x0000,
    
/* 80*/ 0x00000x00000x00000x00000x0000,
    
/* 85*/ 0x00000x00000x00000x00000x0000,
    
/* 90*/ 0x00000x00000x00000x00000x0000,
    
/* 95*/ 0x00000x00000x00000x00000x0000,
    
/*100*/ 0x00000x00000x00000x00000x0000,
    
/*105*/ 0x00000x00000x00000x00000x0000,
    
/*110*/ 0x00000x00000x00000x00000x0000,
    
/*115*/ 0x00000x00000x00000x00000x0000,
    
/*120*/ 0x00000x00000x00000x00000x0000,
    
/*125*/ 0x00000x00000x23020x00c70x00fc,
    
/*130*/ 0x00e90x00e20x00e40x00e00x00e5,
    
/*135*/ 0x00e70x00ea0x00eb0x00e80x00ef,

    
/*140*/ 0x00ee0x00ec0x00c40x00c50x00c9,
    
/*145*/ 0x00e60x00c60x00f40x00f60x00f2,
    
/*150*/ 0x00fb0x00f90x00ff0x00d60x00dc,
    
/*155*/ 0x00a20x00a30x00a50x20a70x0192,
    
/*160*/ 0x00e10x00ed0x00f30x00fa0x00f1,
    
/*165*/ 0x00d10x00aa0x00ba0x00bf0x2310,
    
/*170*/ 0x00ac0x00bd0x00bc0x00a10x00ab,
    
/*175*/ 0x00bb0x25910x25920x25930x2502,
    
/*180*/ 0x25240x25610x25620x25560x2555,
    
/*185*/ 0x25630x25510x25570x255d0x255c,
    
/*190*/ 0x255b0x25100x25140x25340x252c,
    
/*195*/ 0x251c0x25000x253c0x255e0x255f,
    
/*200*/ 0x255a0x25540x25690x25660x2560,
    
/*205*/ 0x25500x256c0x25670x25680x2564,
    
/*210*/ 0x25650x25590x25580x25520x2553,
    
/*215*/ 0x256b0x256a0x25180x250c0x2588,
    
/*220*/ 0x25840x258c0x25900x25800x03b1,
    
/*225*/ 0x03b20x03930x03c00x03a30x03c3,
    
/*230*/ 0x03bc0x03c40x03a60x03b80x2126,
    
/*235*/ 0x03b40x221e0x00f80x03b50x2229,
    
/*240*/ 0x22610x00b10x22650x22640x2320,
    
/*245*/ 0x23210x00f70x22480x00b00x00b7,
    
/*250*/ 0x02d90x221a0x207f0x00b20x25a0,
    
/*255*/ 0x00a0
);

function 
nfo2html($str) {
    global 
$conv_table;
    
$str str_replace("&""&"$str);
    for (
$i 0$i 256$i++) {
        if (
$conv_table[$i] != 0) {
            
$str str_replace(chr($i), "&#".$conv_table[$i].";"$str);
        }
    }
    return 
$str;
}
?>

12 Comments »

  1. andot said,

    May 10, 2005 @ 12:14 pm

    其实我是老师

  2. CoolWolF said,

    May 10, 2005 @ 8:15 pm

    nice job!

  3. UGiA.CN said,

    May 29, 2005 @ 11:09 am

    [...] 区 | 新闻聚合 | 关于 在浏览器中以文本 [...]

  4. liny said,

    July 6, 2005 @ 11:02 am

    Impressive.

  5. phphp said,

    August 7, 2005 @ 2:41 am

    ██▒ ██▒ ███████▒ ██▒ ██▒ ████▒
    ██▒ ██▒ ██▒ ██▒ ██▒ █▒ █▒
    ██▒ ██▒ ██▒ ██▒ ██▒ ██▒ ██▒
    ████████▒ ██████▒ ██▒ ██▒ ██▒ ██▒
    ██▒ ██▒ ██▒ ██▒ ██▒ ██▒ ██▒
    ██▒ ██▒ ██▒ ██▒ ██▒ ██▒ ██▒
    ██▒ ██▒ ██▒ ██▒ ██▒ █▒ █▒
    ██▒ ██▒ ███████▒ ██████▒ ██████▒ ████▒
    还是有对不上的地方,dos下为hello

  6. legend said,

    August 7, 2005 @ 8:58 am

    我並沒有裝這個插件,所以沒有效果

  7. guest said,

    January 3, 2006 @ 10:05 pm

    不能运行?以下是整个原始码
    我的平台是 apache 2.0.55 / PHP5.1.1 / WinXp

    nfo file

    @font-face {
    font-family: nfo;
    font-style: normal;
    font-weight: normal;
    src: url(/nfo.eot);
    }
    .nfo {
    padding: 12px;
    font-family: nfo, courier new;
    font-size: 11px;
    line-height: 1em;
    }

    “, str_replace(” “, ” “, $nfodata))?>

  8. guest said,

    January 3, 2006 @ 10:12 pm

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
    <html xmlns="http://www.w3.org/1999/xhtml&quot; xml:lang="en" lang="en">
    <head>
    <title>nfo file</title>
    <style type="text/css">
    @font-face {
    font-family: nfo;
    font-style: normal;
    font-weight: normal;
    src: url(/nfo.eot);
    }
    .nfo {
    padding: 12px;
    font-family: nfo, courier new;
    font-size: 11px;
    line-height: 1em;
    }
    </style>
    </head>
    <body>
    <pre class="nfo"><?=str_replace("\r", "", $nfodata)?></pre>
    <div class="nfo" style="background-color: #000; color: #fff"><?=str_replace("\n", "<br />", str_replace(" ", "&nbsp;", $nfodata))?></div>
    </body>
    </html>

  9. JulyClyde said,

    January 14, 2007 @ 9:05 pm

    本页上面andot的链接地址错了

  10. ynqjcl said,

    January 25, 2008 @ 3:05 pm

    很喜欢nfo2html但不知道怎么嵌入到论坛程序中,我使用的是PHPWIND,希望能得到你的帮助

  11. http://www.cmstricks.com/blog/2012/06/09/integrating-a-template-into-modx-part-2/ said,

    September 19, 2013 @ 9:29 am

    Hmm is anyone else encountering problems with the images on this blog loading?
    I’m trying to find out if its a problem
    on my end or if it’s the blog. Any suggestions would be greatly appreciated.

  12. source said,

    November 8, 2019 @ 12:19 pm

    UGiA.CN » 在浏览器中以文本方式显示nfo文件:nfo2html https://adriannascloset.blogspot.com/2019/10/keluaran-togel-hongkong-hk-terbaru.html

RSS feed for comments on this post

Leave a Comment