php入门教程一(对文件访问实现)
对文件访问实现的源代码。主要讲到php教程操作文件以及xml文档实例方法。
<?php
// 创建一个新的pdf文档句柄
$pdf = cpdf_open(0);
// 打开一个文件
cpdf_open_file($pdf);
// 开始一个新页面(a4)
cpdf_begin_page($pdf, 595, 842);
// 得到并使用字体对象
$arial = cpdf_findfont($pdf, "arial", "host", 1);
cpdf_setfont($pdf, $arial, 10);
// 输出文字
cpdf_show_xy($pdf, "this is an exam of pdf documents, it is a good lib,",50, 750);
cpdf_show_xy($pdf, "if you like,please try yourself!", 50, 730);
// 结束一页
cpdf_end_page($pdf);
// 关闭并保存文件
cpdf_close($pdf);// 如果要直接输出到客户端的话,把下面的代码加上
$buf = cpdf_get_buffer($pdf);
$len = strlen($buf);
header("content-type: application/pdf");
header("content-length: $len");
header("content-disposition: inline; filename=pie_php.pdf");
print $buf;
cpdf_delete($pdf);
?>
xml文件
<?php
$dom = new domdocument();
$dom->load("order.xsl");
$proc = new xsltprocessor;
$xsl = $proc->importstylesheet($dom);$xml = new domdocument();
$xml->load('order.xml');
$string = $proc->transformtoxml($xml);
echo $string;
?>
order.sls
<?xml version="1.0" encoding='gb2312' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform">
<xsl:output encoding='gb2312'/><xsl:param name="column" select="'sku'"/>
<xsl:param name="order" select="'ascending'"/>
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates select="order">
<xsl:with-param name="sortcolumn" select="$column" />
<xsl:with-param name="sortorder" select="$order" />
</xsl:apply-templates>
</body>
</html>
</xsl:template><xsl:template match="order">
<xsl:param name="sortcolumn" />
<xsl:param name="sortorder" />
<table border="1">
<tr>
<th>订单号</th>
<th>id</th>
<th>说明</th>
<th>价格</th>
<th>数量</th>
<th>合计</th>
</tr>
<xsl:apply-templates select="item">
</xsl:apply-templates>
</table>
</xsl:template>
<xsl:template match="item">
<tr>
<td><xsl:value-of select="../account" /></td>
<td><xsl:value-of select="sku" /></td>
<td><xsl:value-of select="description" /></td>
<td><xsl:value-of select="priceper" /></td>
<td><xsl:value-of select="quantity" /></td>
<td><xsl:value-of select="subtotal" /></td>
</tr>
</xsl:template>
</xsl:stylesheet>
order.xml文件
<?xml version="1.0" encoding='gb2312' ?>
<order>
<account>9900234</account>
<item id="1">
<sku>1234</sku>
<priceper>5.95</priceper>
<quantity>100</quantity>
<subtotal>595.00</subtotal>
<description>www.zzzyk.com</description>
</item>
<item id="2">
<sku>6234</sku>
<priceper>22.00</priceper>
<quantity>10</quantity>
<subtotal>220.00</subtotal>
<description>足球</description>
</item>
<item id="3">
<sku>9982</sku>
<priceper>2.50</priceper>
<quantity>1000</quantity>
<subtotal>2500.00</subtotal>
<description>手机包</description>
</item>
<item id="4">
<sku>3256</sku>
<priceper>389.00</priceper>
<quantity>1</quantity>
<subtotal>389.00</subtotal>
<description>手机</description>
</item>
<numberitems>www.zzzyk.com</numberitems>
<total>3704.00</total>
<orderdate>07/07/2002</orderdate>
<ordernumber>8876</ordernumber>
</order>
补充:Php教程,Php入门