文本的特别要注意效率问题,就一直在找.fon文件的格式说明

数据是以行保存的,文本的特别要注意效率问题,/,就一直在找.fon文件的格式说明,了.fon文件的格式,xml.php,xml类

给我们三个总结的文件操作的类 
自个儿从前写的,不过一直都没时机用了,文本比不上数据库
数码是以行保存的,以\n结尾,注意你输入的数目必得以”\n”结尾的,那是多少个最基本的类成员,文本的非常要小心成效难点,比方您要立异文件的2,3,4行,用:
for($i=2;$i<=4;$i++State of Qatar$this->update($file,$i,$msg卡塔尔国;不比那样的:
$data=$this->read($file);
for($i=2;$i<=4;$i++)$data[$i]=$msg;
$this->write($file,$data); 的

<?
//php教程生成pdf文件代码
/*
生成pdf文件借使的确生成很好,是很复杂的,上边大家来拜候意气风发款完收拾的php生成pdf文件代码吧,他能够把文件文件生成pdf文件也得以选取图片文件生成pdf文件哦。

文件名:xml.class.php

class text{
var $key=”<?die;?>”; //数据爱护
var $keylen; //数据爱抚长度
function text(State of Qatar //类的构造器
{
$this->keylen=strlen($this->lkeylen卡塔尔(قطر‎; //获得爱抚长度
}
function read($file卡塔尔(قطر‎ //读文件,再次回到叁个数组
{
if(file_exists($file)):
$data=@file($file);
$data[0]=substr($data[0],$this->keylen);
return $a;
endif;
}
function write($file,$data=array(State of Qatar卡塔尔 //写文件,数据为多个数组
{
if($fp=fopen($file,”w”)):
flock($fp,3);
fwrite($fp,$this->key);
foeach($data as $v)fwrite($fp,$v);
return true;
endif;
}
function add($file,$msg) 
//向文件最终添扩张少(不设有就先创制文件卡塔尔(قطر‎
{
$a=$this->read($file卡塔尔(قطر‎; //那个不管文件存在不
$a[]=$msg;
return $this->write($file,$a);
}
function insert($file,$n,$msg卡塔尔国 //向第$n前布置数据
{
if($a=$this->read($file)):
$a[$n]=$msg.$a[$n];
return true;
endif;
}
function updata($file,$n,$msg) //更新$n数据
{
if($a=$this->read($file)):
$a[$n]=$msg;
return true;
endif
}
function del($file,$n) //删除$n数据
{
return $this->updata($file,$n,””);
}
}

那款生成pdf文件用到文件有
fpdf.php
chinese.php
picpdf.php

 

 代码如下

*/
//fpdf.php代码

.fon字体文件

May 1, 2007 at 8:45 pm · Filed under
General

数年前痴迷于nfo2pic的时候,就直接在找.fon文件的格式表明,以便从当中间把字体点阵提抽取来,不过还没找到,最后自己和andot不能不抓屏,然后解析图片,把点阵数据提抽出来做成gd能够动用的书体。其后直接未遗弃寻觅,直到今天想起来,找到一点头脑,然后顺藤摘瓜,终于搞理解了.fon文件的格式,参照python的三个本子用php提抽出了.fon字体中的点阵数据,并构建成gd可用的字体。

.fon其实是正规的windows可实施文件(.exeState of Qatar格式,分NE(New
Executable)和PE(Portable
Executable)两种等级次序,字体作为能源存在内部。NE是旧的可实践文件格式,从win95起初的三十位可执路程序就都以PE了。字体财富里的书体都以行业内部的fnt格式,可在这里查看.fnt文件的格式表达。

下边就是自己权且参照Simon
Tatham的dewinfont写的提取程序,pe格式的因为尚未测量试验文件,所以未有剖析,仅供参谋:

下载:
class_fon.php

  1. /**
  2. *
    提取.fon文件中的字体点阵数据,并创立gd中imageloadfont函数可用的书体
  3. *
  4. * @author:
    legend(legendsky@hotmail.com)
  5. * @copyright   UGiA.CN
  6. * @link:
  7. *
  8. * usage:
  9. *
  10. * <?php
  11. * include(‘class_fon.php’);
  12. *
  13. * $fon =
    new Fon(“consol10.fon”);
  14. *
  15. * if ($fon ==
    false)
  16. * {
  17. *     echo $fon->errno .
    “: ” .
    $fon->errstr;
  18. * }
  19. */
  20.  
  21. class Fon
  22. {
  23.     var $file   =
    ”;
  24.     var $stream =
    null;
  25.     var $savepath
    = ”;
  26.  
  27.     var $errno  =
    0;
  28.     var $errstr =
    ”;
  29.  
  30.  
  31.     function fon($file =
    ”, $savepath
    = ”)
  32.     {
  33.         if ($file !==
    ”)
  34.         {
  35.             $this->parse($file,
    $savepath);
  36.         }
  37.     }
  38.  
  39.     function error($errno,
    $errstr)
  40.     {
  41.         $this->errno =
    $errno;
  42.         $this->errstr =
    $errstr;
  43.     }
  44.  
  45.     function parse($file,
    $savepath)
  46.     {
  47.         if (!$file)
  48.         {
  49.             $this->error(1001,
    ‘Please assign a file!’);
  50.             return false;
  51.         }
  52.        
  53.         $this->savepath =
    $savepath ? str_replace(“\\”,
    “/”,
    $savepath) :
    ‘./’;
  54.         $this->savepath .=
    substr($this->savepath, -1) !=
    ‘/’ ?
    ‘/’ :
    ”;
  55.  
  56.         if (is_resource($file))
  57.         {
  58.             $this->stream =
    $file;
  59.         }
  60.         else
  61.         {
  62.             $this->file =
    $file;
  63.             $this->stream =
    file_get_contents($file);
  64.         }
  65.  
  66.         if (!$this->stream)
  67.         {
  68.             $this->error(1002,
    ‘Can not open file!’);
  69.             return false;
  70.         }
  71.  
  72.         $fonts =
    $this->parse_fon();
  73.  
  74.         if (!$fonts)
  75.         {
  76.             return false;
  77.         }
  78.        
  79.         if (!is_dir($this->savepath .
    $fonts[0][‘facename’]))
  80.         {
  81.             @mkdir($this->savepath .
    $fonts[0][‘facename’],
    0700);
  82.         }
  83.  
  84.         foreach ($fontsas$k =>
    $font)
  85.         {
  86.             $filename 
    = $font[‘facename’] .
    sprintf(“_%02d”,
    $k);
  87.             $filename
    .= “_” .
    $font[‘width’] .
    “x” .
    $font[‘height’];
  88.             if ($font[‘italic’])$filename
    .= “_italic”;
  89.             if ($font[‘underline’])$filename
    .= “_underline”;
  90.             if ($font[‘strikeout’])$filename
    .= “_strikeout”;
  91.             $filename
    .= “.fd”;
  92.  
  93.             $this->print_font($font,
    $this->savepath .
    $font[‘facename’] .
    “/” .
    $filename);
  94.         }
  95.     }
  96.  
  97.     function parse_fon()
  98.     {
  99.         $s = &
    new Stream($this->stream);
  100.  
  101.         if (substr($this->stream,
    0, 2) !=
    ‘MZ’)
  102.         {
  103.             $this->error(2001,
    ‘MZ signature not found!’);
  104.             return false;
  105.         }
  106.        
  107.         $neoff =
    $s->dword(0x3c);
    // 标志位offset
  108.  
  109.         if (substr($this->stream,
    $neoff, 2) ==
    ‘NE’)
  110.         {
  111.             return $this->parse_ne($neoff);
  112.         }
  113.         else if(substr($this->stream,
    $neoff, 4) ==
    “PE\0\0”)
  114.         {
  115.             return $this->parse_pe($neoff);
  116.         }
  117.        
  118.         $this->error(2002,
    ‘NE or PE signature not found’);
  119.         return false;
  120.     }
  121.  
  122.     function parse_ne($neoff)
  123.     {
  124.         $stream =
    & $this->stream;
  125.         $s = &
    new Stream($this->stream);
  126.  
  127.         $ret =
    array();
  128.  
  129.         // Find the resource table.
  130.         $rtable =
    $neoff + $s->word($neoff +
    0x24);
  131.  
  132.         // 32h: A shift count that is used to align
    the logical sector. This
  133.         // count is log2 of the segment sector size.
    It is typically 4,
  134.         // although the default count is 9.
  135.         $shift =
    $s->word($rtable);
  136.  
  137.         // Now loop over the rest of the resource
    table.
  138.         $p =
    $rtable + 2;
  139.         while (1)
  140.         {
  141.             $rtype =
    $s->word($p);
  142.            
  143.             // end of resource table
  144.             if ($rtype ==
    0)
  145.             {
  146.                 break;
  147.             }
  148.            
  149.             $count =
    $s->word($p +
    2);         
     
  150.             // type, count, 4 bytes reserved
  151.             $p +=
    8;
  152.            
  153.             for ($i =
    0; $i <
    $count; $i
    ++)
  154.             {
  155.                 $start =
    $s->word($p) <<
    $shift;
  156.                 $size =
    $s->word($p +
    2) <<
    $shift;
  157.                
  158.                 if ($start
    < 0 || $size <
    0 || $start +
    $size > strlen($this->stream))
  159.                 {
  160.                     $this->error(2003,
    ‘Resource overruns file boundaries’);
  161.  
  162.                     return false;
  163.                 }
  164.                
  165.                 // this is an actual font
  166.                 if ($rtype ==
    0x8008)
  167.                 {
  168.                     $font =
    $this->parse_fnt(substr($this->stream,
    $start, $size));
  169.                     //echo “font start at $start, size:
    $size\n”;
  170.                     $ret[] =
    $font;
  171.                 }
  172.  
  173.                 // start, size, flags, name/id, 4 bytes
    reserved
  174.                 $p +=
    12;
  175.             }
  176.         }
  177.        
  178.         return $ret;
  179.     }
  180.    
  181.     function print_font($font,
    $filename)
  182.     {
  183.         $fp  =
    fopen($filename,
    “w”);
  184.         $gdf =
    fopen(substr($filename,
    0, -2) .
    ‘gdf’,
    “w”);
    // GD Font
  185.  
  186.         fwrite($fp,
    “# .fd font description generated by
    dewinfont(php).\n\n”);
  187.         fwrite($fp,
    “facename $font[facename]\n”);
  188.         fwrite($fp,
    “copyright $font[copyright]\n\n”);
  189.         fwrite($fp,
    “height $font[height]\n”);
  190.         fwrite($fp,
    “ascent $font[ascent]\n”);
  191.        
  192.         // gd
  193.         fwrite($gdf,
    “\0\1\0\0”);
  194.         fwrite($gdf,
    “\0\0\0\0”);
  195.         fwrite($gdf,
    chr($font[‘width’]) .
    “\0\0\0”,
    4);
  196.         fwrite($gdf,
    chr($font[‘height’]) .
    “\0\0\0”,
    4);
  197.  
  198.         if ($font[‘height’] ==
    $font[‘pointsize’])fwrite($fp,
    “#”);
  199.         fwrite($fp,
    “pointsize $font[pointsize]\n\n”);
  200.  
  201.         if (!$font[‘italic’])fwrite($fp,
    “#”);       

  202.         fwrite($fp,
    “italic ” .
    ($font[‘italic’] ?
    ‘yes’ :
    ‘no’) .
    “\n”);

  203.  
  204.         if (!$font[‘underline’])fwrite($fp,
    “#”);
  205.         fwrite($fp,
    “underline ” .
    ($font[‘underline’] ?
    ‘yes’ :
    ‘no’) .
    “\n”);
  206.  
  207.         if (!$font[‘strikeout’])fwrite($fp,
    “#”);       

  208.         fwrite($fp,
    “strikeout ” .
    ($font[‘strikeout’] ?
    ‘yes’ :
    ‘no’) .
    “\n”);

  209.        
  210.         if ($font[‘weight’] ==
    400)fwrite($fp,
    “#”);
  211.         fwrite($fp,
    “weight $font[weight]\n\n”);
  212.  
  213.         if ($font[‘charset’] ==
    0)fwrite($fp,
    “#”);
  214.         fwrite($fp,
    “charset $font[charset]\n\n”);     

  215.  

  216.         for ($i =
    0; $i <
    256; $i
    ++)
  217.         {
  218.             fwrite($fp,
    “char $i\nwidth
    ” . $font[‘chars’][$i][‘width’] .
    “\n”);
  219.  
  220.             if ($font[‘chars’][$i][‘width’] !=
    0)
  221.             {
  222.                 for ($j =
    0; $j <
    $font[‘height’];
    $j ++)
  223.                 {
  224.                     $v =
    $font[‘chars’][$i][‘data’][$j];
  225.                     $m =
    1 << ($font[‘chars’][$i][‘width’] –
    1);
  226.                     for ($k =
    0; $k <
    $font[‘chars’][$i][‘width’];
    $k ++)
  227.                     {
  228.                         if ($v &
    $m)
  229.                         {
  230.                             fwrite($fp,
    “M”);
  231.                             fwrite($gdf,
    in_array($i,
    array(7,
    8, 9,
    10, 13,
    26)) ?
    “\0” :
    “\1”);
  232.                         }
  233.                         else
  234.                         {
  235.                             fwrite($fp,
    “.”);
  236.                             fwrite($gdf,
    “\0”);
  237.                         }
  238.  
  239.                         $v =
    $v << 1;
  240.                     }
  241.  
  242.                     fwrite($fp,
    “\n”);
  243.                 }
  244.  
  245.                 fwrite($fp,
    “\n”);
  246.             }
  247.         }
  248.        
  249.         //fwrite($gdf, “(C)2007 UGiA.CN”);
  250.         fclose($gdf);
  251.         fclose($fp);
  252.     }
  253.  
  254.     function parse_fnt($stream)
  255.     {
  256.         $s = &
    new Stream($stream);
  257.        
  258.         $font =
    array();
  259.  
  260.         $font[‘version’] =
    $s->word(0);
  261.         $font[‘copyright’] =
    substr($stream,
    6, 60);
  262.         $ftype =
    $s->word(0x42);
  263.  
  264.         if ($ftype &
    1)
  265.         {
  266.             // This font is a vector font
  267.             return;
  268.         }
  269.        
  270.         // face name offset
  271.         $off_facename = $s->dword(0x69);
  272.  
  273.         if ($off_facename < 0 ||
    $off_facename > strlen($stream))
  274.         {
  275.             // Face name not contained within font
    data
  276.             return;
  277.         }
  278.  
  279.         $font[‘facename’] =
    $s->read_str($off_facename);
  280.         $font[‘pointsize’] =
    $s->word(0x44);
  281.         $font[‘ascent’] =
    $s->word(0x4a);
  282.         $font[‘width’] =
    0; // max
    width
  283.         $font[‘height’] =
    $s->word(0x58);
  284.         $font[‘italic’] =
    $s->byte(0x50);
  285.         $font[‘underline’] =
    $s->byte(0x51);
  286.         $font[‘strikeout’] =
    $s->byte(0x52);
  287.         $font[‘weight’] =
    $s->word(0x53);
  288.         $font[‘charset’] =
    $s->byte(0x55);
  289.        
  290.         // Read the char table.    
  291.         if ($font[‘version’] ==
    0x200)
  292.         {
  293.             $ctstart =
    0x76;
  294.             $ctsize =
    4;
  295.         }
  296.         else
  297.         {
  298.             $ctstart =
    0x94;
  299.             $ctsize =
    6;
  300.         }
  301.  
  302.         $maxwidth
    = 0;
  303.  
  304.         $font[‘chars’] =
    array();
  305.  
  306.         for ($i =
    0; $i <
    256; $i
    ++)
  307.         {
  308.             $font[‘chars’][$i][‘data’] =
    array_fill(0,
    $font[‘height’],
    0);
  309.         }
  310.  
  311.         $firstchar
    = $s->byte(0x5f);
  312.         $lastchar
    = $s->byte(0x60);
  313.         #print “$firstchar,$lastchar “;
  314.         for ($i =
    $firstchar; $i <=
    $lastchar; $i
    ++)
  315.         {
  316.             $entry =
    $ctstart + $ctsize *
    ($i –
    $firstchar);
  317.             $w =
    $s->word($entry);
  318.             $font[‘chars’][$i][‘width’] =
    $w;
  319.             $font[‘width’] =
    $w > $font[‘width’] ?
    $w : $font[‘width’];
  320.            
  321.             if ($ctsize ==
    4)
  322.             {
  323.                 $off =
    $s->word($entry +
    2);
  324.             }
  325.             else
  326.             {
  327.                 $off =
    $s->dword($entry +
    2);
  328.             }
  329.            
  330.             $widthbytes = floor(($w +
    7) /
    8);
  331.             //echo $widthbytes . ” “;
  332.             for ($j =
    0; $j <
    $font[‘height’];
    $j ++)
  333.             {
  334.                 for ($k =
    0; $k <
    $widthbytes; $k
    ++)
  335.                 {
  336.                     $bytepos =
    $off + $k *
    $font[‘height’] +
    $j;
  337.                    
  338.                     $font[‘chars’][$i][‘data’][$j] =
    $font[‘chars’][$i][‘data’][$j] <<
    8;
  339.                     $font[‘chars’][$i][‘data’][$j] =
    $font[‘chars’][$i][‘data’][$j] |
    $s->byte($bytepos);
  340.                 }
  341.  
  342.                 $font[‘chars’][$i][‘data’][$j] =
    $font[‘chars’][$i][‘data’][$j] >>
    (8 *
    $widthbytes – $w);
  343.                 //echo
    $font[‘chars’][$i][‘data’][$j] . ” “;
  344.             }          

  345.         }

  346.  
  347.         //print_r($font);
  348.  
  349.         return $font;
  350.     }
  351. }
  352.  
  353. class Stream
  354. {
  355.     var $stream =
    ”;
  356.  
  357.     function stream($stream)
  358.     {
  359.         $this->stream =
    $stream;
  360.     }
  361.  
  362.     function byte($offset)
  363.     {
  364.         return ord($this->stream{$offset});
  365.     }
  366.  
  367.     function word($offset)
  368.     {
  369.         return $this->byte($offset +
    0) +
    256 * $this->byte($offset +
    1);
  370.     }
  371.  
  372.     function dword($offset)
  373.     {
  374.         return $this->word($offset +
    0) |
    ($this->word($offset +
    2) <<
    16);
  375.     }
  376.  
  377.     function read_str($offset)
  378.     {
  379.         $pos =
    strpos($this->stream,
    “\0”,
    $offset);
  380.         if ($pos !==
    false)
  381.         {
  382.             return substr($this->stream,
    $offset, $pos –
    $offset);
  383.         }
  384.  
  385.         return substr($this->stream,
    $offset);
  386.     }
  387. }

小心:程序施行后会生成三个用字体名字命名的文书夹,里面含有若干pd和gbf文件,.gbf为可供gd所使用字体。

仿效资料:
NE格式:
PE格式:

FNT字体文件格式:
Simon
Tatham的主页:http://www.chiark.greenend.org.uk/~sgtatham/fonts/
python版的dewinfont程序:http://www.chiark.greenend.org.uk/~sgtatham/fonts/dewinfont

/***
* *
* 文件名: xml.php *
* 作 用: xml类,康健中,暂只扶持三级节点 *
* 作 者: loking(biyees) *
* *
* example 读取数据: *
* $xml = new xml(“dbase.xml”,’table’); *
* $data=$xml->xml_fetch_array(); *
* echo ”<pre style=\”font-size:12px;\”>”; *
* print_r($data); *
* *
******************/
class xml{
var $dbase; //数据库,要读取的XML文件
var $dbname;
//数据库名称,顶层成分,与数据库文件名称意气风发致
var $dbtable; //数据表,要获取的节点
var $parser; //剖析器
var $vals; //属性
var $index; //索引
var $dbtable_array;//节点数组
var $array; //下级节点的数组
var $result; //重临的结果
var $querys;
 
function xml($dbase,$dbtable){
$this->dbase=$dbase;
$this- >dbname=”document”;
$this- >dbtable=$dbtable;
$data=$this- >ReadXml($this->dbase);
if(!$data){
die( ”不可能读取 $this->dbname.xml”卡塔尔(قطر‎;
}
$this- >parser = xml_parser_create();
xml_parser_set_option($this-
>parser,XML_OPTION_CASE_FOLDING,0);
xml_parser_set_option($this-
>parser,XML_OPTION_SKIP_WHITE,1);
xml_parse_into_struct($this-
>parser,$data,$this->vals,$this->index);
xml_parser_free($this- >parser);
//遍历索引,筛选出要取值的节点 节点名:$dbtable
foreach ($this- >index as
$key=>$val) {
if ($key == $this- >dbtable) {
//得到节点数组
$this- >dbtable_array = $val;
} else {
continue;
}
}
for ($i=0; $i < count($this->dbtable_array); $i+=2) {
$offset = $this- >dbtable_array[$i] + 1;
$len = $this- >dbtable_array[$i + 1] – $offset;
//array_slice(卡塔尔 重临依照 offset 和 length 参数所钦赐的 array
数组中的意气风发段种类。
//所取节点下级数组
$value=array_slice($this- >vals,$offset,$len);
//获得有效数组,归拢为结果数组
$this- >array[]=$this->parseEFF($value);
}
return true;
}
//将XML文件读入并赶回字符串
function ReadXml($file)
{
return file_get_contents($file);
}
//获得有效数组
function parseEFF($effective) {
for ($i=0; $i < count($effective); $i++){
$effect[$effective[$i][ “tag”]] = $effective[$i][“value”];
}
return $effect;
}
//xml_query(方法,条件,多规格时逻辑运算符and or
or,总量量数组,插入或更新的数组卡塔尔
function xml_query($method,$condition,$if=’and’,$array=array())
{
if(($method==’select’)||($method==’count’)){
return $this- >xml_select($method,$condition,$if);
} elseif($method==’insert’) {
return $this- >xml_insert($condition,$if,$array);
} elseif($method==’update’) {
return $this- >xml_update($condition,$if,$array);
}
}
//取得xml数组
function xml_fetch_array($condition,$if)
{
//$this- >querys++;
$row = $this- >array; //伊始化数据数组
if($condition) {
//是不是有标准化,如有条件则变动切合条件的数组
//生成条件数组,条件格式 田野同志,operator,match
$condition=explode(
”,”,$condition卡塔尔(قطر‎;//条件数组
$cs=count($condition)/3; //条件数
for($i=0;$i <$cs;$i++){
$conditions[]=array(
”field”=>$condition[$i*3],”operator”=>$condition[$i*3+1],”match”=>$condition[$i*3+2]);
}
//echo count($row);
for($r=0;$r <count($row);$r++){
for($c=0;$c <$cs;$c++){
//$i++;
$condition=$conditions[$c]; //当前条件
$field=$condition[‘field’]; //字段
$operator=$condition[ “operator”];//运算符
$match=$condition[‘match’]; //匹配
if(($operator==’=’) &&($row[$r][$field]==$match)){
$true++;//若条件切合,切合数加1
} elseif(($operator==’!=’) &&($row[$r][$field]!=$match)){
$true++;//若条件符合,相符数加1
} elseif(($operator==’ <’)&&($row[$r][$field]<$match)){
$true++;//若条件切合,相符数加1
} elseif(($operator==’ <=’)&&($row[$r][$field]<=$match)){
$true++;//若条件符合,切合数加1
} elseif(($operator==’ >’)&&($row[$r][$field]>$match)){
$true++;//若条件切合,切合数加1
} elseif(($operator==’ >’)&&($row[$r][$field]>=$match)){
$true++;//若条件符合,切合数加1
}
}
//遵照条件取值
if($if==’and’){
//借使多规格为and,当相符数等于条件数时,生成数组
if($true==$cs){
$result[]=$row[$r];
}
} else {
//即便多规格为or,当有相符纪录时,生成数组
if($true!=0){
$result[]=$row[$r];
}
}
//echo $true;
//echo ”<pre style=\”font-size:12px;\text-align:left\”>”;
//print_r($true);
$true=0;//相符条件数归零,步入下风度翩翩轮循环
}
} else {
$result=$this- >array;
}
//echo ”<pre style=\”font-size:12px;\text-align:left\”>”;
//print_r($this- >result);
return $result;
}
//筛选或总计
function xml_select($method,$condition,$if)
{
$result=$this- >xml_fetch_array($condition,$if);
if($method==’select’){
return $result;
} else {
return count($result);
}
}
//插入数据
function xml_insert($condition,$if,$array)
{
$data=$this- >xml_fetch_array($condition,$ifState of Qatar;//总的数量据数组
$data[]=$array; //插入后的总的数量量数组
$this- >array=$data; //更新总的数量组
$this- >WriteXml($data);
}
//拿到更新的XML并改写
function xml_update($condition,$if,$array){
$datas=$this- >array; //总量据数组
$subtract=$this- >xml_fetch_array($condition,$if卡塔尔国;//要翻新的数组
//echo ”<pre style=\”font-size:12px;\text-align:left\”>”;
//print_r($data);
//print_r($datas);
//echo ”每条记下中有“.count($datas[0]).”个值<br>”;
for($i=0;$i <count($datas);$i++){
$data=$datas[$i];
//echo ”原始记录中的第“.$i.”条<br>”;
foreach($data as $k= >$v){
//echo ”-第“.$i.”条的“.$k.”值为“.$v.”<br>”;
//echo ”–要物色的数组“.$k.”值为“.$subtract[0][$k].”<br>”;
if($v==$subtract[0][$k]){
$is++;
}
}
if($is==count($data)){
//echo ”—-与第“.$i.”条符合<br>”;
$datas[$i]=$array;
//array_splice($datas,$i,$i+1);
}
//echo ”原始记录中的第“.$i.”条与要物色的有“.$is.”相称<br>”;
//echo ”原始记录中的第“.$i.”条截止<br>”;
$is=0;
}
//array_splice($datas,2,2+1,$array);
//echo ”<pre style=\”font-size:12px;\text-align:left\”>”;
//print_r($datas);
$this- >array=$datas;
$this- >WriteXml($datas);
 
}
//写入XML文件(全体写入卡塔尔国
function WriteXml($array)
{
if(!is_writeable($this- >dbase)){
die( ”不能写入“.$this->dbname.”.xml”卡塔尔(قطر‎;
}
$xml.= ”<?xml version=\”1.0\” encoding=\”gb2312\”?>\r\n”;
$xml.= ”<$this->dbname>\r\n”;
for($i=0;$i <count($array);$i++){
$xml.= ”<$this->dbtable>\r\n”;
foreach($array[$i] as $k= >$s){
$xml.= ”<$k>$s</$k>\r\n”;
}
$xml.= ”</$this->dbtable>\r\n”;
}
$xml.= ”</$this->dbname>”;
dbase,”w’>$fp=@fopen($this->dbase,”w”);
flock($fp, LOCK_EX);
rewind($fp);
fputs($fp,$xml);
fclose($fp);
}
//逐行写入xml(小编试着写入10000行,以为没叁遍写入快,所以没用这种写入措施卡塔尔(قطر‎
function WriteLine($array)
{
if(!is_writeable($this- >dbase)){
die( ”无法写入“.$this->dbname.”.xml”State of Qatar;
}
dbase,”w’>$fp=@fopen($this->dbase,”w”);
rewind($fp);
flock($fp, LOCK_EX);
fputs($fp, ”<?xml version=\”1.0\”
encoding=\”gb2312\”?>\r\n”);
fputs($fp, ”<$this->dbname>\r\n”);
for($i=0;$i <count($array);$i++){
fputs($fp, ”<$this->dbtable>\r\n”);
$xml.= ”<$this->dbtable>\r\n”;
foreach($array[$i] as $k= >$s){
fputs($fp, ”<$k>$s</$k>\r\n”);
}
fputs($fp, ”</$this->dbtable>\r\n”);
}
fputs($fp, ”</$this->dbname>”);
fclose($fp);
}
}
?>
 

define(‘fpdf_version’,’1.6′);

选拔办法:

class fpdf
{
var $page;               //current page number
var $n;                  //current object number
var $offsets;            //array of object offsets
var $buffer;             //buffer holding in-memory pdf
var $pages;              //array containing pages
var $state;              //current document state
var $compress;           //compression flag
var $k;                  //scale factor (number of points in user
unit)
var $deforientation;     //default orientation
var $curorientation;     //current orientation
var $pageformats;        //available page formats
var $defpageformat;      //default page format
var $curpageformat;      //current page format
var $pagesizes;          //array storing non-default page sizes
var $wpt,$hpt;           //dimensions of current page in points
var $w,$h;               //dimensions of current page in user unit
var $lmargin;            //left margin
var $tmargin;            //top margin
var $rmargin;            //right margin
var $bmargin;            //page break margin
var $cmargin;            //cell margin
var $x,$y;               //current position in user unit
var $lasth;              //height of last printed cell
var $linewidth;          //line width in user unit
var $corefonts;          //array of standard font names
var $fonts;              //array of used fonts
var $fontfiles;          //array of font files
var $diffs;              //array of encoding differences
var $fontfamily;         //current font family
var $fontstyle;          //current font style
var $underline;          //underlining flag
var $currentfont;        //current font info
var $fontsizept;         //current font size in points
var $fontsize;           //current font size in user unit
var $drawcolor;          //commands for drawing color
var $fillcolor;          //commands for filling color
var $textcolor;          //commands for text color
var $colorflag;          //indicates whether fill and text colors are
different
var $ws;                 //word spacing
var $images;             //array of used images
var $pagelinks;          //array of links in pages
var $links;              //array of internal links
var $autopagebreak;      //automatic page breaking
var $pagebreaktrigger;   //threshold used to trigger page breaks
var $inheader;           //flag set when processing header
var $infooter;           //flag set when processing footer
var $zoommode;           //zoom display mode
var $layoutmode;         //layout display mode
var $title;              //title
var $subject;            //subject
var $author;             //author
var $keywords;           //keywords
var $creator;            //creator
var $aliasnbpages;       //alias for total number of pages
var $pdfversion;         //pdf version number

插入一条记下

/*******************************************************************************
*                                                                             
*
*                               public
methods                                 *
*                                                                             
*
*******************************************************************************/
function fpdf($orientation=’p’, $unit=’mm’, $format=’a4′)
{
 //some checks
 $this->_dochecks();
 //initialization of properties
 $this->page=0;
 $this->n=2;
 $this->buffer=”;
 $this->pages=array();
 $this->pagesizes=array();
 $this->state=0;
 $this->fonts=array();
 $this->fontfiles=array();
 $this->diffs=array();
 $this->images=array();
 $this->links=array();
 $this->inheader=false;
 $this->infooter=false;
 $this->lasth=0;
 $this->fontfamily=”;
 $this->fontstyle=”;
 $this->fontsizept=12;
 $this->underline=false;
 $this->drawcolor=’0 g’;
 $this->fillcolor=’0 g’;
 $this->textcolor=’0 g’;
 $this->colorflag=false;
 $this->ws=0;
 //standard fonts
 $this->corefonts=array(‘courier’=>’courier’,
‘courierb’=>’courier-bold’, ‘courieri’=>’courier-oblique’,
‘courierbi’=>’courier-boldoblique’,
  ‘helvetica’=>’helvetica’, ‘helveticab’=>’helvetica-bold’,
‘helveticai’=>’helvetica-oblique’,
‘helveticabi’=>’helvetica-boldoblique’,
  ‘times’=>’times-roman’, ‘timesb’=>’times-bold’,
‘timesi’=>’times-italic’, ‘timesbi’=>’times-bolditalic’,
  ‘symbol’=>’symbol’, ‘zapfdingbats’=>’zapfdingbats’);
 //scale factor
 if($unit==’pt’)

 代码如下

 

require_once(‘xml.class.php’);

  $this->k=1;
 elseif($unit==’mm’)
  $this->k=72/25.4;
 elseif($unit==’cm’)
  $this->k=72/2.54;
 elseif($unit==’in’)
  $this->k=72;
 else
  $this->error(‘incorrect unit: ‘.$unit);
 //page format
 $this->pageformats=array(‘a3’=>array(841.89,1190.55),
‘a4’=>array(595.28,841.89), ‘a5’=>array(420.94,595.28),
  ‘letter’=>array(612,792), ‘legal’=>array(612,1008));
 if(is_string($format))
  $format=$this->_getpageformat($format);
 $this->defpageformat=$format;
 $this->curpageformat=$format;
 //page orientation
 $orientation=strtolower($orientation);
 if($orientation==’p’ || $orientation==’portrait’)
 {
  $this->deforientation=’p’;
  $this->w=$this->defpageformat[0];
  $this->h=$this->defpageformat[1];
 }
 elseif($orientation==’l’ || $orientation==’landscape’)
 {
  $this->deforientation=’l’;
  $this->w=$this->defpageformat[1];
  $this->h=$this->defpageformat[0];
 }
 else
  $this->error(‘incorrect orientation: ‘.$orientation);
 $this->curorientation=$this->deforientation;
 $this->wpt=$this->w*$this->k;
 $this->hpt=$this->h*$this->k;
 //page margins (1 cm)
 $margin=28.35/$this->k;
 $this->setmargins($margin,$margin);
 //interior cell margin (1 mm)
 $this->cmargin=$margin/10;
 //line width (0.2 mm)
 $this->linewidth=.567/$this->k;
 //automatic page break
 $this->setautopagebreak(true,2*$margin);
 //full width display mode
 $this->setdisplaymode(‘fullwidth’);
 //enable compression
 $this->setcompression(true);
 //set default pdf version number
 $this->pdfversion=’1.3′;
}

$xml = new xml(“exemple.xml”,”item”);

function setmargins($left, $top, $right=null)
{
 //set left, top and right margins
 $this->lmargin=$left;
 $this->tmargin=$top;
 if($right===null)
  $right=$left;
 $this->rmargin=$right;
}

$newarray = array(

function setleftmargin($margin)
{
 //set left margin
 $this->lmargin=$margin;
 if($this->page>0 && $this->x<$margin)
  $this->x=$margin;
}

“title”=>”XML标题“,

function settopmargin($margin)
{
 //set top margin
 $this->tmargin=$margin;
}

“text”=>”PHP的XML类测试!“

function setrightmargin($margin)
{
 //set right margin
 $this->rmargin=$margin;
}

);

function setautopagebreak($auto, $margin=0)
{
 //set auto page break mode and triggering margin
 $this->autopagebreak=$auto;
 $this->bmargin=$margin;
 $this->pagebreaktrigger=$this->h-$margin;
}

$insert=$xml->xml_query(‘insert’,”,”,$newarray卡塔尔(قطر‎;//第二及第两个变量地方是原则,留空表示在结尾插入

function setdisplaymode($zoom, $layout=’continuous’)
{
 //set display mode in viewer
 if($zoom==’fullpage’ || $zoom==’fullwidth’ || $zoom==’real’ ||
$zoom==’default’ || !is_string($zoom))
  $this->zoommode=$zoom;
 else
  $this->error(‘incorrect zoom display mode: ‘.$zoom);
 if($layout==’single’ || $layout==’continuous’ || $layout==’two’ ||
$layout==’default’)
  $this->layoutmode=$layout;
 else
  $this->error(‘incorrect layout display mode: ‘.$layout);
}

修正记录

function setcompression($compress)
{
 //set page compression
 if(function_exists(‘gzcompress’))
  $this->compress=$compress;
 else
  $this->compress=false;
}

require_once(‘xml.class.php’);

function settitle($title, $isutf8=false)
{
 //title of document
 if($isutf8)
  $title=$this->_utf8toutf16($title);
 $this->title=$title;
}

$xml = new xml(“exemple.xml”,”item”);

function setsubject($subject, $isutf8=false)
{
 //subject of document
 if($isutf8)
  $subject=$this->_utf8toutf16($subject);
 $this->subject=$subject;
}

$array = array(

function setauthor($author, $isutf8=false)
{
 //author of document
 if($isutf8)
  $author=$this->_utf8toutf16($author);
 $this->author=$author;
}

“title”=>”XML标题“,

function setkeywords($keywords, $isutf8=false)
{
 //keywords of document
 if($isutf8)
  $keywords=$this->_utf8toutf16($keywords);
 $this->keywords=$keywords;
}

“text”=>”PHP的XML类测试!“

function setcreator($creator, $isutf8=false)
{
 //creator of document
 if($isutf8)
  $creator=$this->_utf8toutf16($creator);
 $this->creator=$creator;
}

);

function aliasnbpages($alias='{nb}’)
{
 //define an alias for total number of pages
 $this->aliasnbpages=$alias;
}

$insert=$xml->xml_query(‘update’,’title,=,20年后世界将会怎么?‘,’and’,$array卡塔尔;//title标签等于xxx的用$array替换(能够建唯生机勃勃属性的标签,比方id,那样就能够改正某一条记下)

function error($msg)
{
 //fatal error
 die(‘<b>fpdf error:</b> ‘.$msg);
}

剔除记录

function open()
{
 //begin document
 $this->state=1;
}

 代码如下