NFO2TXT (php version)

由于nfo文件的特殊性,需要特殊的字体或编码才能够正常显示。如果你用计事本查看,ascii码大于127的字符是乱码一堆。有没有办法用记事本来查看nfo呢?
看到ibic原创的nfo2txt (C语言版),我根据他的映射表做了这个php小程序。将nfo转换成unicode文本文件,外观基本一样。

需要设置一下记事本的字体为courier new或其他等宽字体才能正常查看。
演示: http://0day.ugia.net/program/nfo2pic/nfo2txt.php

原创文章,转载请注明出处。

<?php
/**
* NFO TO TEXT (php version)

* Special thanks to ibic@9down
* @author legend(PASiOcn@msn.com)
*/

$conv_table = array(
/*  0*/ 0x263a0x263b0x26650x26660x2663
/*  5*/ 0x26600x25cf0x25d80x26420x2640
/* 10*/ 0x00000x263c0x25ba0x00000x2195
/* 15*/ 0x203c0x00b60x00a70x00f50x21a8
/* 20*/ 0x21910x21930x21920x21900x221f
/* 25*/ 0x21940x25b20x25bc0x00000x0000
/* 30*/ 0x00000x00000x00000x00000x0000
/* 35*/ 0x00000x00000x00000x00000x0000
/* 40*/ 0x00000x00000x00000x00000x0000
/* 45*/ 0x00000x00000x00000x00000x0000
/* 50*/ 0x00000x00000x00000x00000x0000
/* 55*/ 0x00000x00000x00000x00000x0000
/* 60*/ 0x00000x00000x00000x00000x0000
/* 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*/ 0x00000x00000x00000x00000x0000
/*130*/ 0x00000x00000x00000x00000x0000
/*135*/ 0x00000x00000x00000x00000x0000
/*140*/ 0x00000x00000x00000x00000x0000
/*145*/ 0x00000x00000x00000x00000x0000
/*150*/ 0x00000x00000x00000x00000x0000
/*155*/ 0x00000x00000x00000x00000x0000
/*160*/ 0x00000x00000x00000x00000x0000
/*165*/ 0x00000x00000x00000x00000x0000
/*170*/ 0x00000x00000x00000x00000x0000
/*175*/ 0x00000x25910x25920x25930x2502
/*180*/ 0x25240x25610x25620x25560x2555
/*185*/ 0x25630x25510x25570x255d0x255c
/*190*/ 0x255b0x25100x25140x25340x252c
/*195*/ 0x251c0x25000x253c0x255e0x255f
/*200*/ 0x255a0x25540x25690x25660x2560
/*205*/ 0x25500x256c0x25670x25680x2564
/*210*/ 0x25650x25590x25580x25520x2553
/*215*/ 0x256a0x256a0x25180x250c0x2588
/*220*/ 0x25840x258c0x25900x25800x03b1
/*225*/ 0x03b20x00000x00000x00000x0000
/*230*/ 0x00000x00000x00000x00000x0000
/*235*/ 0x00000x00000x00000x00000x0000
/*240*/ 0x00000x00000x00000x00000x0000
/*245*/ 0x00000x00000x00000x25cb0x2014
/*250*/ 0x20130x00000x00000x00000x25a0
/*255*/ 0x0000
);
if(
is_uploaded_file($_FILES['filename']['tmp_name']))
{
    
$fname $_FILES['filename']['name'].".txt";
    
$str   file_get_contents($_FILES['filename']['tmp_name']);
    
$txt   conv_nfo($str);
    
header('Content-type: application/x-octet-stream');
    
header('Content-disposition: attachment; filename=' $fname);
    print 
$txt;
}
else
{
    echo 
"<html><head><style type='text/css'>body,input{font-size:11px;font-family:tahoma}</style></head><body>";
    echo 
"<form action='' method='post' enctype='multipart/form-data'>\n";
    echo 
"<input type='file' name='filename' size='50' />";
    echo 
"<input type='submit' value='GET TXT' />";
    echo 
"</form>";
    echo 
"</body>";
}
//cove str
function conv_nfo($str)
{
    global 
$conv_table;
    for(
$i 0$i strlen($str); $i ++)
    {
        if(
$conv_table[ord($str[$i])] == 0)
        {
            
$output .= code2utf(ord($str[$i]));
        }
        else
        {
            
$output .= code2utf($conv_table[ord($str[$i])]);
        }
    }
     
    return 
$output;
}
//code 2 unicode
function code2utf($num)
{
    if(
$num<128)
        return 
chr($num);
    if(
$num<1024)
        return 
chr(($num>>6)+192).chr(($num&63)+128);
    if(
$num<32768)
        return 
chr(($num>>12)+224).chr((($num>>6)&63)+128).chr(($num&63)+128);
    if(
$num<2097152)
        return 
chr($num>>18+240).chr((($num>>12)&63)+128).chr(($num>>6)&63+128). chr($num&63+128);
    return 
'';
}
?>

效果:
nfo2txt

2 Comments »

  1. andot said,

    February 16, 2005 @ 5:16 pm

    不错,在firefox里面可以正常显示了。不过在IE里面还是不行,IE里面似乎对等宽字体不支持。

  2. free ringtones said,

    December 3, 2006 @ 11:58 pm

    free ringtones http://www.forumprofi.de/forum7715/ free ringtones

RSS feed for comments on this post

Leave a Comment