无忧启动论坛

标题: unifont.hex減肥php腳本 [打印本页]

作者: roytam1    时间: 2012-3-25 17:47
标题: unifont.hex減肥php腳本
使用 CP***.TXT 來限定新的 unifont.hex 所擁有的字數。
CP***.TXT 可在 unicode.org 下載: http://unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/

用法:
php tbl4slim.php [TXT檔...]
如:
php tbl4slim.php CP936.TXT CP950.TXT

新生成的為 unifont.hex.slim

  1. <?php

  2. $txtfiles = array();
  3. $txtary = array();

  4. $chrs = array();
  5. $newunifonthex = array();

  6. if($_SERVER['argc'] < 2) {
  7.         fwrite(STDERR, "Usage: ".$_SERVER['argv'][0]." {TXT files...}\n");
  8.         exit(2);
  9. }
  10. if(!file_exists('./unifont.hex')) {
  11.         fwrite(STDERR, "Error: unifont.hex not found!\n");
  12.         exit(1);
  13. }

  14. for($i=1;$i<$_SERVER['argc'];++$i) {
  15.         if(!file_exists($_SERVER['argv'][$i])) {
  16.                 fwrite(STDERR, "Warning: ".$_SERVER['argv'][$i]." is not found.\n");
  17.         } else {
  18.                 $txtfiles[] = file($_SERVER['argv'][$i]);
  19.         }
  20. }
  21. foreach($txtfiles as $t) {
  22.         foreach($t as $l) {
  23.                 $txtary = explode("\t",$l);
  24.                 if(isset($txtary[1]) && substr($txtary[1],0,2)=='0x') $chrs[$txtary[1]] = 1;
  25.         }
  26. }

  27. $txtary = file('./unifont.hex');
  28. foreach($txtary as $l) {
  29.         if(isset($chrs['0x'.substr($l,0,4)])) $newunifonthex[] = $l;
  30. }

  31. $fp = fopen('./unifont.hex.slim','wb');
  32. fwrite($fp,implode('',$newunifonthex));
  33. fclose($fp);
复制代码





欢迎光临 无忧启动论坛 (http://wuyou.net/) Powered by Discuz! X3.3