<?xml version="1.0" encoding="gb2312"?>
<rss version="2.0">
<channel>
<title><![CDATA[海湛湛兮]]></title>
        <image>
        <title>http://hi.baidu.com</title>
        <link>http://hi.baidu.com</link>
        <url>http://img.baidu.com/img/logo-hi.gif</url>
        </image>
<description><![CDATA[Java，湛湛然蓝色也]]></description>
<link>http://hi.baidu.com/lhbmqq</link>
<language>zh-cn</language>
<generator>www.baidu.com</generator>
<ttl>5</ttl>


<item>
        <title><![CDATA[PHP取参]]></title>
        <link><![CDATA[http://hi.baidu.com/lhbmqq/blog/item/ad9c8013f45a30876538dbdd.html]]></link>
        <description><![CDATA[
		
		&lt;?PHP<br>
//取得index.php传来的的历史观测数据起始参数 from 结束参数 to<br>
$from&nbsp;&nbsp;  =&nbsp;&nbsp;  $_POST['from'] ;echo $from;echo &quot;ok&quot;;<br>
$to&nbsp;&nbsp;  =&nbsp;&nbsp;  $_POST['to'] ;<br>
?&gt; 
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/lhbmqq/blog/category/Php">Php</a>&nbsp;<a href="http://hi.baidu.com/lhbmqq/blog/item/ad9c8013f45a30876538dbdd.html#comment">查看评论</a>]]></description>
        <pubDate>2009年02月25日 星期三  00:18</pubDate>
        <category><![CDATA[Php]]></category>
        <author><![CDATA[lhbmqq]]></author>
		<guid>http://hi.baidu.com/lhbmqq/blog/item/ad9c8013f45a30876538dbdd.html</guid>
</item>

<item>
        <title><![CDATA[学习 JpGraph 一点心得]]></title>
        <link><![CDATA[http://hi.baidu.com/lhbmqq/blog/item/81a21408d490ea37e824885a.html]]></link>
        <description><![CDATA[
		
		前言：JpGraph 是一款用 PHP 编写的作图框架软件（需要 GD 库支持），它功能丰富，调用简单，尽管如此，有些图表的细节需要仔细查资料研究，本人在做项目时把遇到的问题和解决方法与大家分享。<br>
安装<br>
JpGraph 的安装十分简便 ：到 http://sourceforge.net/projects/jpgraph/ 下载，解压到应用程序的根路径即可。<br>
使用范例一<br>
这次我们以 Examples 目录下的 example0.php 为例来讲解一下如何初步使用 JpGraph。example0.php 代码如下：<br>
<br>
代码片段<br>
&lt;?php<br>
include (&quot;../jpgraph.php&quot;); //必须要引用的文件<br>
include (&quot;../jpgraph_line.php&quot;); //包含曲线图文件<br>
<br>
// y 轴数据，以数组形式赋值<br>
$ydata = array(11,3,8,12,5,1,9,13,5,7);<br>
<br>
// 创建 Graph 类，350 为宽度，250 长度，auto：表示生成的缓存文件名是该文件的文件名+扩展名(.jpg .png .gif ……)<br>
$graph = new Graph(350,250,&quot;auto&quot;);<br>
<br>
// 设置刻度类型，x轴刻度可作为文本标注的直线刻度，y轴为直线刻度<br>
$graph-&gt;SetScale(&quot;textlin&quot;);<br>
<br>
// 创建坐标类，将y轴数据注入<br>
$lineplot=new LinePlot($ydata);<br>
<br>
// y 轴连线设定为蓝色<br>
$lineplot-&gt;SetColor(&quot;blue&quot;);<br>
<br>
// 坐标类注入图标类<br>
$graph-&gt;Add($lineplot);<br>
<br>
// 显示图<br>
$graph-&gt;Stroke(); ?&gt;<br>
<br>
<br>
使用范例二<br>
代码片段<br>
&lt;?php<br>
$ydata = array(11,3,8,12,5,1,9,13,5,7);<br>
// x 轴数据，作为 x 轴标注<br>
$xdata = array('2007-3-01','2007-3-03','2007-3-05','2007-3-07','2007-3-09','2007-3-01','2007-3-11','2007-3-13','2007-3-15')；<br>
$graph = new Graph(350,150,&quot;auto&quot;);<br>
$graph-&gt;SetScale(&quot;textlin&quot;);<br>
<br>
// 设置图表大标题<br>
$graph-&gt;title-&gt;Set(&lsquo;Example&rsquo;);<br>
$lineplot = new LinePlot($ydata);<br>
$graph-&gt;Add($lineplot);<br>
<br>
// 设置图表灰度四周边距，顺序为左右上下<br>
$graph-&gt;img-&gt;SetMargin(60,20,20,50);<br>
<br>
// 设置输出文件格式为 jpg，缺省为 png<br>
$graph-&gt;img-&gt;SetImgFormat( &quot;jpeg&quot;);<br>
<br>
// y 轴坐标描点形状为菱形<br>
$lineplot-&gt; mark-&gt;SetType(MARK_DIAMOND );<br>
<br>
// 加入 x 轴标注<br>
$graph-&gt;xaxis-&gt;SetTickLabels($xdata);<br>
<br>
// 定位 x 轴标注垂直位置应在最下方<br>
$graph-&gt;xaxis-&gt;SetPos(&quot;min&quot;);<br>
<br>
// 设置 x 轴标注文字为斜体，粗体，6号小字<br>
$graph-&gt;xaxis-&gt;SetFont(FF_ARIAL,FS_BOLD,6);<br>
<br>
// 设置 x 轴标注文字 45 度倾斜。注：前面 SetFont 必须为 FF_ARIAL<br>
$graph-&gt;xaxis-&gt;SetLabelAngle(45);<br>
<br>
// x 轴刻度间隔为 2<br>
$graph-&gt;xaxis-&gt;SetTextLabelInterval(2);<br>
<br>
// 标题和 y 轴标题字体为标准字体<br>
$graph-&gt;title-&gt;SetFont(FF_FONT1,FS_BOLD,2);<br>
$graph-&gt;yaxis-&gt;title-&gt;SetFont(FF_FONT1,FS_BOLD);<br>
<br>
// y 轴坐标点连线为蓝色加深加粗<br>
$lineplot-&gt;SetColor(&quot;blue:0.5&quot;);<br>
$lineplot-&gt;SetWeight(2);<br>
$graph-&gt;yaxis-&gt;SetColor(&quot;black&quot;);<br>
$graph-&gt;yaxis-&gt;SetWeight(2);<br>
<br>
// 阴影效果<br>
$graph-&gt;SetShadow();<br>
<br>
// 显示图形<br>
$graph-&gt;Stroke(); ?&gt;<br>
<br>
可能遇到的问题<br>
由于涉及到图象输出，所以在某些GUI配置不正确的系统中就可能会遇到一些显示问题。最常见的是&ldquo;找不到 XX 字体（比如FF_ARIAL 字体）&rdquo;，遇到这种情况，我们可采取以下步骤解决：<br>
1. 首先到具备这些字体的系统（比如 Windows 等系统）中或可以下载这些字体的地方把相关的字体罗列出来，然后把他们复制到某个我们 WEB 程序可以访问的目录（假定为 /www/fonts ）内。<br>
以 FF_ARIAL 字体为例，我们可以在 Windows 系统的 $windows/fonts 找到 arialbd.ttf 、arialbi.ttf、ariali.ttf、arial.ttf 这几个字体文件，然后将其复制到 /www/fonts。<br>
2. 修改jpgraph.php文件。<br>
找到<br>
DEFINE('TTF_DIR','/usr/X11R6/lib/X11/fonts/truetype/');<br>
这一行，将其改为<br>
DEFINE('TTF_DIR',&rsquo;/www/fonts/&rsquo;);<br>
重新刷新即可。 
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/lhbmqq/blog/category/Php">Php</a>&nbsp;<a href="http://hi.baidu.com/lhbmqq/blog/item/81a21408d490ea37e824885a.html#comment">查看评论</a>]]></description>
        <pubDate>2009年02月22日 星期日  23:05</pubDate>
        <category><![CDATA[Php]]></category>
        <author><![CDATA[lhbmqq]]></author>
		<guid>http://hi.baidu.com/lhbmqq/blog/item/81a21408d490ea37e824885a.html</guid>
</item>

<item>
        <title><![CDATA[Catchable fatal error: Object of class variant could not be converted to string]]></title>
        <link><![CDATA[http://hi.baidu.com/lhbmqq/blog/item/6d831ff3f2908fcc0a46e08b.html]]></link>
        <description><![CDATA[
		
		if( $rs-&gt;Fields['MoveToday_Date_Text']-&gt;value==NULL){<br>
&nbsp;&nbsp;&nbsp;  echo '为NULL';<br>
&nbsp;&nbsp;  }else{<br>
&nbsp;&nbsp;&nbsp;  echo $rs-&gt;Fields['MoveToday_Date_Text']-&gt;value;<br>
&nbsp;&nbsp;  } 
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/lhbmqq/blog/category/Php">Php</a>&nbsp;<a href="http://hi.baidu.com/lhbmqq/blog/item/6d831ff3f2908fcc0a46e08b.html#comment">查看评论</a>]]></description>
        <pubDate>2009年02月22日 星期日  14:22</pubDate>
        <category><![CDATA[Php]]></category>
        <author><![CDATA[lhbmqq]]></author>
		<guid>http://hi.baidu.com/lhbmqq/blog/item/6d831ff3f2908fcc0a46e08b.html</guid>
</item>

<item>
        <title><![CDATA[PHP连接access数据库]]></title>
        <link><![CDATA[http://hi.baidu.com/lhbmqq/blog/item/829beefadb0007d9b48f3182.html]]></link>
        <description><![CDATA[
		
		&lt;?PHP <br>
/* <br>
创建ADO连接 <br>
*/ <br>
$conn = @new COM(&quot;ADODB.Connection&quot;) or die (&quot;ADO Connection faild.&quot;); <br>
$connstr = &quot;DRIVER={Microsoft <a target="_blank" href="http://www.jb51.net/list/list_105_1.htm"><font color="red">Access</font></a> Driver (*.mdb)}; DBQ=&quot; . realpath(&quot;DATUM/cnbt.mdb&quot;); <br>
$conn-&gt;Open($connstr); <br>
/* <br>
创建记录集查询 <br>
*/ <br>
$rs = @new COM(&quot;ADODB.RecordSet&quot;); <br>
$rs-&gt;Open(&quot;select * from dbo_dirs&quot;,$conn,1,3); <br>
/* <br>
循环读取数据 <br>
*/ <br>
while(!$rs-&gt;eof){ <br>
echo &quot;$rs-&gt;Fields[&lsquo;title&rsquo;]-&gt;Value; <br>
echo &quot;&lt;br/&gt;&quot;; <br>
$rs-&gt;Movenext();     //将记录集指针下移 <br>
} <br>
$rs-&gt;close();  <br>
?&gt; 
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/lhbmqq/blog/category/Php">Php</a>&nbsp;<a href="http://hi.baidu.com/lhbmqq/blog/item/829beefadb0007d9b48f3182.html#comment">查看评论</a>]]></description>
        <pubDate>2009年02月22日 星期日  14:10</pubDate>
        <category><![CDATA[Php]]></category>
        <author><![CDATA[lhbmqq]]></author>
		<guid>http://hi.baidu.com/lhbmqq/blog/item/829beefadb0007d9b48f3182.html</guid>
</item>

<item>
        <title><![CDATA[rs.open &#34;select * from dndj&#34;,conn,1,3&#34;的含义]]></title>
        <link><![CDATA[http://hi.baidu.com/lhbmqq/blog/item/7fd4362de26edc33349bf7bd.html]]></link>
        <description><![CDATA[
		
		<font style="font-size: 14px; " >rs.Open SQL,Conn,A,B(代表你上面的1，3)<br>
<br>
A: <br>
<br>
ADOPENFORWARDONLY(=0)  <br>
只读,且当前数据记录只能向下移动<br>
<br>
ADOPENKEYSET(=1)       <br>
只读,当前数据记录可自由移动<br>
<br>
ADOPENDYNAMIC(=2)       <br>
可读写,当前数据记录可自由移动<br>
<br>
ADOPENSTATIC(=3)      <br>
可读写,当前数据记录可自由移动,可看到新增记录<br>
<br>
B:<br>
<br>
ADLOCKREADONLY(=1)     <br>
缺省锁定类型，记录集是只读的，不能修改记录<br>
<br>
ADLOCKPESSIMISTIC(=2)  <br>
悲观锁定，当修改记录时，数据提供者将尝试锁定记录以确保成功地编辑记录。只要编辑一开始，则立即锁住记录。<br>
<br>
ADLOCKOPTIMISTIC(=3)   <br>
乐观锁定 ，直到用Update方法提交更新记录时才锁定记录。<br>
<br>
ADLOCKBATCHOPTIMISTIC(=4)  <br>
批量乐观锁定，允许修改多个记录，只有调用UpdateBatch方法后才锁定记录。<br>
<br>
当不需要改动任何记录时，应该使用只读的记录集，这样提供者不用做任何检测。<br>
对于一般的使用，乐观的锁定可能是最好的选择，因为记录只被锁定一小段时间，<br>
数据在这段时间被更新。这减少了资源的使用。<br>
<br>
<br>
<br>
RS.OPEN SQL,CONN,A,B <br>
参数A为设定游标的类型，其取值为： <br>
0 仅向前游标，只能向前浏览记录，不支持分页、Recordset、BookMark <br>
1 键集游标，其他用户对记录说做的修改将反映到记录集中，但其他用户增加或删除记录不会反映到记录集中。支持分页、Recordset、BookMark <br>
2 动态游标功能最强，但耗资源也最多。用户对记录说做的修改，增加或删除记录都将反映到记录集中。支持全功能浏览。 <br>
3 静态游标，只是数据的一个快照，用户对记录说做的修改，增加或删除记录都不会反映到记录集中。支持向前或向后移动 <br>
<br>
<br>
参数B为记录集的锁定类型，其取值为： <br>
1 锁定类型，默认的，只读，不能作任何修改 <br>
2 当编辑时立即锁定记录，最安全的方式 <br>
3 只有在调用Update方法时才锁定记录集，而在此前的其他操作仍可对当前记录进行更改、插入和删除等 <br>
4 当编辑时记录不会被锁定，而更改、插入和删除是在批处理方式下完成的 <br>
<br>
打开数据记录集方法其实不止一种，但是我们用的最多的就是 <br>
rs.open sql,1,1的方法，可是后面的数字参数很多人不解其意，下面我们来介绍一下。 <br>
其实open方法后面有多个参数 <br>
CursorType LockType CommandType <br>
比如 rs.open sql,1,1 <br>
也可以写成 <br>
rs.cursorType = 1 <br>
rs.LockType = 1 <br>
rs.open sql <br>
其中CursorType代表从一个表或者一个SQL查询结果返回的记录。 <br>
这个参数有四个值分别是： <br>
adOpenForwardOnly 表示只允许在记录集内的记录间往前移动。这个是缺省值。 <br>
adOpenKeyset 反映由其它用户所做的对记录的改变或者删除动作，但并不反映由其它用户做作的添加新记录的动作。 <br>
adOpenDynamic 反映由其它用户所做的对记录的改变或者删除动作，包括添加的新记录 <br>
adOpenStatic 不反映其它用户对记录所做的修改，添加，删除动作。 <br>
这四个值VBSCRIPT预定义位 <br>
adOpenForwardOnly = 0 <br>
adOpenKeyset = 1 <br>
adOpenDynamic = 2 <br>
adOpenStatic = 3 <br>
<br>
lockType 表示当打开记录集时，数据提供者用于锁定数据库的类型： <br>
adLockReadOnly 数据不能改变，这是缺省值！ <br>
adLockPessimistic 数据提供者在开始编辑数据的时候锁定记录 <br>
adLockOptimistic 仅当调用update方法时，数据提供者锁定记录 <br>
adLockBatchOptimistic 用于批处理修改 <br>
他们的常量值定义分别是： <br>
adLockReadOnly = 1 <br>
adLockPessimistic = 2 <br>
adLockOptimistic = 3 <br>
adLockBatchOptimistic = 4</font> 
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/lhbmqq/blog/category/Php">Php</a>&nbsp;<a href="http://hi.baidu.com/lhbmqq/blog/item/7fd4362de26edc33349bf7bd.html#comment">查看评论</a>]]></description>
        <pubDate>2009年02月22日 星期日  13:50</pubDate>
        <category><![CDATA[Php]]></category>
        <author><![CDATA[lhbmqq]]></author>
		<guid>http://hi.baidu.com/lhbmqq/blog/item/7fd4362de26edc33349bf7bd.html</guid>
</item>

<item>
        <title><![CDATA[jpgraph的一个使用例子及汉字乱码的解决方法]]></title>
        <link><![CDATA[http://hi.baidu.com/lhbmqq/blog/item/b6fa2a1245e15b56f919b8f4.html]]></link>
        <description><![CDATA[
		
		<div >
<div class="article_c">
<p>　　jpgraph的一个使用例子及汉字乱码的解决方法</p>
<p><clk> 最近因为<nobr style="border-bottom: 1px dotted rgb(102, 0, 255); text-decoration: underline; color: rgb(102, 0, 255); background-color: transparent;" >工作</nobr>原因，需要做一些图表出来，上网查了一下，PHP中主要的做图工具有两种。一个是jpgraph,一个是image_graph.</clk></p>
<p>　　JPGRAPH是PHP世界里一款非常方便的做各种图表的工作，柱状图、饼图、雷达图等，基本上对所有的图表无所不能。</p>
<p><clk> 在PEAR中，也有一款做图表的工具，叫image_graph,这个工具功能也是非常强大，但jpgraph和image_graph比起来的最大好处，就是有很多的例子和非常详细的文档<nobr style="border-bottom: 1px dotted rgb(102, 0, 255); text-decoration: underline; color: rgb(102, 0, 255); background-color: transparent;" >说明</nobr>，这就使jpgraph用起来是相当的方便。</clk></p>
<p>　　最后决定选用jpgraph。</p>
<p>　　下面是一段代码。同时在用的过程中遇到了汉字乱码的问题，原因已经找到，也和大家说明一下。</p>
<p>　　如果您在使用jpgraph的过程遇到了什么问题，可以MAIL给我，大家一直探讨。同时，如果你有什么使用心得，也希望您能够发到LAMPER上，让更多的人分享你的经验。</p>
<p><code>&lt;?php　<br>
include (&quot;../jpgraph.php&quot;);　<br>
include (&quot;../jpgraph_line.php&quot;);　<br>
<br>
$ydata = array(11,3,8,12,5,1,9,13,5,7);　<br>
$y2data = array(354,200,265,99,111,91,198,225,293,251);　<br>
$datax = array(&quot;2006-01-01&quot;,&quot;2006-01-01&quot;,&quot;2006-01-01&quot;,&quot;2006-01-01&quot;,&quot;2006-01-01&quot;,&quot;2006-01-01&quot;,&quot;2006-01-01&quot;,&quot;2006-01-01&quot;,&quot;2006-01-01&quot;,&quot;2006-01-01&quot;); 　<br>
<br>
// Create the graph. These two calls are always required　<br>
$graph = new Graph(800,400,&quot;auto&quot;);　　<br>
$graph-&gt;img-&gt;SetMargin(40,40,20,40);　<br>
<br>
$graph-&gt;title-&gt;SetFont(FF_SIMSUN,FS_BOLD);　<br>
$title = &quot;展示pv/展示ip&quot;;　<br>
$graph-&gt;title-&gt;Set($title);　<br>
<br>
$graph-&gt;SetScale(&quot;textlin&quot;);　<br>
$graph-&gt;SetY2Scale(&quot;lin&quot;);　<br>
<br>
$graph-&gt;xaxis-&gt;title-&gt;Set(&quot;时间&quot;);　<br>
$graph-&gt;xaxis-&gt;title-&gt;SetFont(FF_SIMSUN,FS_BOLD);　<br>
$graph-&gt;xaxis-&gt;SetTickLabels($datax);　<br>
<br>
$graph-&gt;yaxis-&gt;title-&gt;Set(&quot;展示pv&quot;);　<br>
$graph-&gt;yaxis-&gt;SetColor(&quot;blue&quot;);　<br>
$graph-&gt;yaxis-&gt;title-&gt;SetFont(FF_SIMSUN,FS_BOLD);　<br>
<br>
$graph-&gt;y2axis-&gt;title-&gt;Set(&quot;展示IP&quot;);　<br>
$graph-&gt;y2axis-&gt;SetColor(&quot;orange&quot;);　<br>
$graph-&gt;y2axis-&gt;title-&gt;SetFont(FF_SIMSUN,FS_BOLD);　<br>
<br>
$lineplot=new LinePlot($ydata);　<br>
$lineplot-&gt;SetColor(&quot;blue&quot;);　<br>
$lineplot-&gt;SetWeight(2);　<br>
$lineplot-&gt;SetLegend(&quot;展示pv&quot;);　<br>
$graph-&gt;legend-&gt;SetFont(FF_SIMSUN,FS_BOLD);　<br>
<br>
$lineplot2=new LinePlot($y2data);　<br>
$lineplot2-&gt;SetColor(&quot;orange&quot;);　<br>
$lineplot2-&gt;SetWeight(2);　<br>
$lineplot2-&gt;SetLegend(&quot;展示ip&quot;);　<br>
<br>
<br>
$graph-&gt;Add($lineplot);　<br>
$graph-&gt;AddY2($lineplot2);　<br>
<br>
// Display the graph　<br>
$graph-&gt;Stroke();　<br>
?&gt;　</code></p>
<p>　　注意SetFont方法，如果你的文件编码是gb2312,SetFont方法的第一个参数为FF_SIMSUN即可正常显示汉字</p>
<p>　　如果你的文件编码为utf-8，还需加一句$title = iconv(&quot;UTF-8&quot;, &quot;gb2312&quot;, $title)</p>
<p>　　在jpgraph.php中，有这么一段语句：</p>
<p><code>elseif( $aFF === FF_SIMSUN ) {<br>
// Do Chinese conversion<br>
if( $this-&gt;g2312 == null ) {<br>
include_once 'jpgraph_gb2312.php' ;<br>
$this-&gt;g2312 = new GB2312toUTF8();<br>
}<br>
return $this-&gt;g2312-&gt;gb2utf8($aTxt);<br>
}</code>就是说，jpgraph默认显示汉字时是把汉字编码认为gb2312,转化为utf-8以后再显示。</p>
<p>　　这样的话，如果你的文件编码是gb2312,SetFont方法的第一个参数为FF_SIMSUN即可</p>
<p>　　如果你是utf-8编码你还需要先把汉字编码转化为gb2312，这样你的汉字才可以正常显示。</p>
<p>　　网上有种方法是修改jpgraph.php文件，我本人不提倡这样做，我们应该尽量修改自己实际应用程序，而尽量少修改基本程序。</p>
</div>
</div> 
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/lhbmqq/blog/category/Php">Php</a>&nbsp;<a href="http://hi.baidu.com/lhbmqq/blog/item/b6fa2a1245e15b56f919b8f4.html#comment">查看评论</a>]]></description>
        <pubDate>2009年02月18日 星期三  21:44</pubDate>
        <category><![CDATA[Php]]></category>
        <author><![CDATA[lhbmqq]]></author>
		<guid>http://hi.baidu.com/lhbmqq/blog/item/b6fa2a1245e15b56f919b8f4.html</guid>
</item>

<item>
        <title><![CDATA[JPGraph中文乱码问题]]></title>
        <link><![CDATA[http://hi.baidu.com/lhbmqq/blog/item/295c3c2ecbe172574ec2260a.html]]></link>
        <description><![CDATA[
		
		<span >
<p>JPGraph处理有中文字符时都会转成utf8编码后显示，我们只需注释掉相关的代码就可以了。</p>
<p>Dotproject苷特图中文乱码解决具体步骤如下：</p>
<p>1。修改jpgraph库</p>
<p>打开dotproject \lib\jpgraph\jpgraph\src\jpgraph.php文件，找到下面代码段</p>
<p>&nbsp;&nbsp;&nbsp;  function Convert($aTxt,$aFF) {<br>
 if( LANGUAGE_CYRILLIC ) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;  if( CYRILLIC_FROM_WINDOWS ) {<br>
&nbsp;&nbsp; $aTxt = convert_cyr_string($aTxt, &quot;w&quot;, &quot;k&quot;); <br>
&nbsp;&nbsp;&nbsp;&nbsp;  }<br>
&nbsp;&nbsp;&nbsp;&nbsp;  $isostring = convert_cyr_string($aTxt, &quot;k&quot;, &quot;i&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;  $unistring = LanguageConv::iso2uni($isostring);<br>
&nbsp;&nbsp;&nbsp;&nbsp;  return $unistring;<br>
 }/* 注释掉下面代码段<br>
 elseif( $aFF === FF_SIMSUN ) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;  // Do Chinese conversion<br>
&nbsp;&nbsp;&nbsp;&nbsp;  if( $this-&gt;g2312 == null ) {<br>
&nbsp;&nbsp; include_once 'jpgraph_gb2312.php' ;<br>
&nbsp;&nbsp; $this-&gt;g2312 = new GB2312toUTF8();<br>
&nbsp;&nbsp;&nbsp;&nbsp;  }<br>
&nbsp;&nbsp;&nbsp;&nbsp;  return $this-&gt;g2312-&gt;gb2utf8($aTxt);<br>
 }<br>
 elseif( $aFF === FF_CHINESE ) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;  if( !function_exists('iconv') ) {<br>
&nbsp;&nbsp; JpGraphError::Raise('Usage of FF_CHINESE (FF_BIG5) font family requires that your PHP setup has the iconv() function. By default this is not compiled into PHP (needs the &quot;--width-iconv&quot; when configured).');<br>
&nbsp;&nbsp;&nbsp;&nbsp;  }<br>
&nbsp;&nbsp;&nbsp;&nbsp;  return iconv('BIG5','UTF-8',$aTxt);<br>
 }注释到此结束*/<br>
 else <br>
&nbsp;&nbsp;&nbsp;&nbsp;  return $aTxt;<br>
&nbsp;&nbsp;&nbsp;  }</p>
<p>2.修改dotproject中用到jpgraph的模块</p>
<p>  a.  改project模块</p>
<p>打开dotproject\modules\projects\gantt.php文件，修改文件中下面的代码</p>
<p>将所有</p>
<p>arialbd.ttf</p>
<p>用</p>
<p>simsum.ttc</p>
<p>替换</p>
<p>将所有</p>
<p>FF_ARIAL</p>
<p>用</p>
<p>FF_SIMSUN</p>
<p>替换</p>
<p>注释掉下面的代码</p>
<p> //if ( $locale_char_set=='utf-8' &amp;&amp; function_exists(&quot;utf8_decode&quot;) ) {<br>
 // $name = utf8_decode($name);<br>
 //}</p>
<p>b.同理修改dotproject\modules\tasks\gantt.php文件</p>
</span> 
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/lhbmqq/blog/category/Php">Php</a>&nbsp;<a href="http://hi.baidu.com/lhbmqq/blog/item/295c3c2ecbe172574ec2260a.html#comment">查看评论</a>]]></description>
        <pubDate>2009年02月17日 星期二  22:16</pubDate>
        <category><![CDATA[Php]]></category>
        <author><![CDATA[lhbmqq]]></author>
		<guid>http://hi.baidu.com/lhbmqq/blog/item/295c3c2ecbe172574ec2260a.html</guid>
</item>

<item>
        <title><![CDATA[PHP如何读写文件]]></title>
        <link><![CDATA[http://hi.baidu.com/lhbmqq/blog/item/988cb28b8319ce789f2fb400.html]]></link>
        <description><![CDATA[
		
		PHP读写文件，就如同<a target="_blank" href="http://www.cnbruce.com/blog/index.asp?vt=search&amp;key=FSO%E7%BB%84%E4%BB%B6%E4%B9%8B%E6%96%87%E4%BB%B6%E6%93%8D%E4%BD%9C" class="blog_content">ASP中使用FSO进行文件的读写操作</a>。当然在ASP中FSO仅对于运行当前程序的服务器磁盘上文件进行读写（很明显就是需要获得物理路径），然而PHP可以通过FTP或HTTP打开文件进行读写。<br>
<br>
<strong>一，PHP如何读取文件</strong><br>
<br>
PHP读取文件可以读取当前服务器或远程服务器中的文件。其步骤是：打开文件、读文件和关闭文件。<br>
<br>
<strong>1，PHP如何打开文件</strong><br>
<br>
使用PHP<strong>函数fopen()</strong>打开一个文件，fopen()一般使用2个参数表示打开文件的路径和文件模式。比如：<br>
<br>
<table width="100%" cellspacing="1" border="0" bgcolor="#cccccc">
    <tbody>
        <tr>
            <td bgcolor="#efefef"><br>
            $fp=fopen(&quot;../cnbruce.txt&quot;,'w');</td>
        </tr>
    </tbody>
</table>
<br>
其中 &quot;../cnbruce.txt&quot; 就表示打开的cnbruce.txt文件的路径（相对当前执行程序文件的路径），'w'表示以只写的方式打开该文本文件。<br>
<br>
附录：fopen()函数的文件模式总结<br>
<br>
r&nbsp;&nbsp;&nbsp;&nbsp; 只读&mdash;&mdash;读模式，打开文件，从文件头开始读<br>
r+&nbsp;&nbsp;&nbsp;&nbsp; 可读可写方式打开文件，从文件头开始读写<br>
w&nbsp;&nbsp;&nbsp;&nbsp; 只写&mdash;&mdash;写方式打开文件，同时把该文件内容清空，把文件指针指向文件开始处。如果该文件已经存在，将删除文件已有内容；如果该文件不存在，则建立该文件<br>
w+&nbsp;&nbsp;&nbsp;&nbsp; 可读可写方式打开文件，同时把该文件内容清空，把文件指针指向文件开始处。如果该文件不存在，则建立该文件<br>
a&nbsp;&nbsp;&nbsp;&nbsp; 追加&nbsp;&nbsp;&nbsp;&nbsp; 以只写方式打开文件，把文件指针指向文件末尾处。如果该文件不存在，则建立该文件<br>
a+&nbsp;&nbsp;&nbsp;&nbsp; 追加&nbsp;&nbsp;&nbsp;&nbsp; 以可读可写方式打开文件，把文件指针指向文件末尾处。如果该文件不存在，则建立该文件<br>
b&nbsp;&nbsp;&nbsp;&nbsp; 二进制&nbsp;&nbsp;&nbsp;&nbsp; 用于于其他模式进行连接。建议使用该选项，以获得更大程度的可移植性<br>
<br>
注意，如果fopen()函数调用失败，函数将返回false。否则返回指针数据。所以一般在打开了文件后\读写文件前需要检测下文件是否存在。<br>
<br>
<table width="100%" cellspacing="1" border="0" bgcolor="#cccccc">
    <tbody>
        <tr>
            <td bgcolor="#efefef"><br>
            &lt;?php<br>
            @ $fp=fopen(&quot;http://www.cnbruce.com/abc123&quot;,'w');<br>
            if (!$fp)<br>
            {<br>
            &nbsp;&nbsp;&nbsp;&nbsp; echo'文件不存在';<br>
            &nbsp;&nbsp;&nbsp;&nbsp; exit;<br>
            }<br>
            ?&gt;</td>
        </tr>
    </tbody>
</table>
<br>
其中@符号表示PHP将抑制所有由当前函数调用产生的错误。<br>
<br>
<strong>2，PHP如何读文件</strong><br>
<br>
在PHP打开了文件之后就需要对文件进行读取，一般是使用<strong>fgets()函数</strong>。<br>
<br>
该函数可以从文件中每次读取一行内容，其不断读入数据，值到遇到本行的换行符，或者全文的结束符号EOF。<br>
<br>
介于fgets()函数只能读取一行数据，所以若需要读取文件的所有数据，须使用循环语句来完成。比如：<br>
<br>
<table width="100%" cellspacing="1" border="0" bgcolor="#cccccc">
    <tbody>
        <tr>
            <td bgcolor="#efefef"><br>
            while (!feof($fp))<br>
            {<br>
            &nbsp;&nbsp;&nbsp;&nbsp; $bruce=fgets($fp);<br>
            &nbsp;&nbsp;&nbsp;&nbsp; echo $bruce;<br>
            }</td>
        </tr>
    </tbody>
</table>
<br>
其中<strong>feof()函数</strong>是用来检测文件是否结束的。该函数唯一参数就是文件指针（即$fp对应打开的文件）。<br>
<br>
当然，在PHP中还可以使用<strong>readfile()函数</strong>一次读取整个文件。该函数包括了打开文件、读取文件并输出到浏览器中和关闭文件。比如：<br>
<br>
<table width="100%" cellspacing="1" border="0" bgcolor="#cccccc">
    <tbody>
        <tr>
            <td bgcolor="#efefef"><br>
            &lt;?php<br>
            $bruce=readfile(&quot;http://www.cnbruce.com&quot;);<br>
            echo $bruce;<br>
            ?&gt;</td>
        </tr>
    </tbody>
</table>
<br>
<strong>3，PHP如何关闭文件</strong><br>
<br>
使用<strong>函数fclose()</strong>就可以将文件关闭。<br>
<br>
<strong>二，PHP如何写数据到文件</strong><br>
<br>
与PHP读取文件一样，PHP写入文件也需要：打开文件、写入数据和关闭文件。打开和关闭文件的方法上面已经说明，那PHP中写入数据到文件是怎样的呢。<br>
<br>
使用<strong>fwrite()函数</strong>，比如<strong>fwrite(文件路径,写入内容)</strong>：<br>
<br>
<br>
<table width="100%" cellspacing="1" border="0" bgcolor="#cccccc">
    <tbody>
        <tr>
            <td bgcolor="#efefef"><br>
            &lt;?php<br>
            $bruce=fopen(&quot;http://www.cnbruce.com/&quot;,&quot;r&quot;);<br>
            if(!$bruce)<br>
            {<br>
            &nbsp;&nbsp;&nbsp;&nbsp; echo'文件不存在';<br>
            &nbsp;&nbsp;&nbsp;&nbsp; exit;<br>
            }<br>
            while (!feof($bruce))<br>
            {<br>
            &nbsp;&nbsp;&nbsp;&nbsp; $rose=fgets($bruce);<br>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $james=fopen(&quot;index.htm&quot;,&quot;a&quot;);<br>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fwrite($james,$rose);<br>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fclose($james);<br>
            }<br>
            fclose($bruce);<br>
            ?&gt;<br>
            &lt;a href=&quot;index.htm&quot;&gt;将cnbruce.com的内容生成了本地文件&lt;/a&gt;</td>
        </tr>
    </tbody>
</table>
<br>
<br>
了解了PHP的读写文件，就可以把最简单的数据存入文本保存了。也就可以做个<a target="_blank" href="http://www.cnbruce.com/code/story.asp" class="blog_content">故事接龙</a>了。<br>
<br>
=============================<br>
其他有用的文件函数：<br>
<br>
<strong>file_exists()：</strong>查看文件是否存在，返回布尔值<br>
<strong>filesize()：</strong>查看文件大小，可直接echo输出<br>
<strong>unlink()：</strong>删除文件，注意PHP中没有delete函数。<br>
<br>
<br>
<br>
<code><font color="#000000"><font color="#ff8000">/**<br>
*  写文件<br>
* @param&nbsp;&nbsp;&nbsp;&nbsp; string&nbsp;&nbsp; $file&nbsp;&nbsp;&nbsp; 文件路径<br>
* @param&nbsp;&nbsp;&nbsp;&nbsp; string&nbsp;&nbsp; $str&nbsp;&nbsp;&nbsp;&nbsp; 写入内容<br>
*  @param&nbsp;&nbsp;&nbsp;&nbsp; char&nbsp;&nbsp;&nbsp;&nbsp; $mode&nbsp;&nbsp;&nbsp; 写入模式<br>
*/<br>
</font><font color="#007700">function  </font><font color="#0000bb">wfile</font><font color="#007700">(</font><font color="#0000bb">$file</font><font color="#007700">,</font><font color="#0000bb">$str</font><font color="#007700">,</font><font color="#0000bb">$mode</font><font color="#007700">=</font><font color="#dd0000">'w'</font><font color="#007700">)<br>
{<br>
&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000bb">$oldmask </font><font color="#007700">= @</font><font color="#0000bb">umask</font><font color="#007700">(</font><font color="#0000bb">0</font><font color="#007700">);<br>
&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000bb">$fp </font><font color="#007700">= @</font><font color="#0000bb">fopen</font><font color="#007700">(</font><font color="#0000bb">$file</font><font color="#007700">,</font><font color="#0000bb">$mode</font><font color="#007700">);<br>
&nbsp;&nbsp;&nbsp;&nbsp; @</font><font color="#0000bb">flock</font><font color="#007700">(</font><font color="#0000bb">$fp</font><font color="#007700">, </font><font color="#0000bb">3</font><font color="#007700">);<br>
&nbsp;&nbsp;&nbsp;&nbsp; if(!</font><font color="#0000bb">$fp</font><font color="#007700">)<br>
&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Return  </font><font color="#0000bb">false</font><font color="#007700">;<br>
&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp; else<br>
&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @</font><font color="#0000bb">fwrite</font><font color="#007700">(</font><font color="#0000bb">$fp</font><font color="#007700">,</font><font color="#0000bb">$str</font><font color="#007700">);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @</font><font color="#0000bb">fclose</font><font color="#007700">(</font><font color="#0000bb">$fp</font><font color="#007700">);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @</font><font color="#0000bb">umask</font><font color="#007700">(</font><font color="#0000bb">$oldmask</font><font color="#007700">);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Return  </font><font color="#0000bb">true</font><font color="#007700">;<br>
&nbsp;&nbsp;&nbsp;&nbsp; }<br>
}  </font></font></code> 
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/lhbmqq/blog/category/Php">Php</a>&nbsp;<a href="http://hi.baidu.com/lhbmqq/blog/item/988cb28b8319ce789f2fb400.html#comment">查看评论</a>]]></description>
        <pubDate>2009年02月17日 星期二  21:59</pubDate>
        <category><![CDATA[Php]]></category>
        <author><![CDATA[lhbmqq]]></author>
		<guid>http://hi.baidu.com/lhbmqq/blog/item/988cb28b8319ce789f2fb400.html</guid>
</item>

<item>
        <title><![CDATA[用 PHP 读取文件的正确方法]]></title>
        <link><![CDATA[http://hi.baidu.com/lhbmqq/blog/item/59ae1af7bcf87125730eec5b.html]]></link>
        <description><![CDATA[
		
		<blockquote>了解如何使用 PHP 的各种文件函数。查看诸如 <code>fopen</code>、<code>fclose</code> 和 <code>feof</code> 之类的基本文件函数；了解诸如 <code>fgets</code>、<code>fgetss</code> 和 <code>fscanf</code> 之类的读取函数。并且发现用一两行代码处理整个文件的函数。</blockquote>
<p><a name="N10057"><span class="atitle">让我们算一算有多少种方法</span></a></p>
<p>处 理诸如 PHP 之类的现代编程语言的乐趣之一就是有大量的选项可用。PHP 可以轻松地赢得 Perl 的座右铭&ldquo;There's more than one way to do it&rdquo;（并非只有一种方法可做这件事），尤其是在文件处理上。但是在这么多可用的选项中，哪一种是完成作业的最佳工具？当然，实际答案取决于解析文件的目 标，因此值得花时间探究所有选项。</p>
<br>
<table width="100%" cellspacing="0" cellpadding="0" border="0">
    <tbody>
        <tr>
            <td><img height="1" width="100%" src="http://www.ibm.com/i/v14/rules/blue_rule.gif"><br>
            <img height="6" width="8" border="0" src="http://www.ibm.com/i/c.gif"></td>
        </tr>
    </tbody>
</table>
<table cellspacing="0" cellpadding="0" align="right" class="no-print">
    <tbody>
        <tr align="right">
            <td><img height="4" width="100%" src="http://www.ibm.com/i/c.gif"><br>
            <table height="20" width="51" cellspacing="0" cellpadding="0" border="0">
                <tbody>
                    <tr>
                        <td valign="middle"> </td>
                        <td valign="top" align="right"> </td>
                    </tr>
                </tbody>
            </table>
            </td>
        </tr>
    </tbody>
</table>
<br>
<br>
<p><a name="N10060"><span class="atitle">传统的 fopen 方法</span></a></p>
<p><code>fopen</code> 方法可能是以前的 C 和 C++ 程序员最熟悉的，因为如果您使用过这些语言，那么它们或多或少都是您已掌握多年的工具。对于这些方法中的任何一种，通过使用 <code>fopen</code>（用于读取数据的函数）的标准方法打开文件，然后使用 <code>fclose</code> 关闭文件，如清单 1 所示。</p>
<br>
<a name="list1"><strong>清单 1. 用 fgets 打开并读取文件</strong></a><br>
<table width="50%" cellspacing="0" cellpadding="0" border="0">
    <tbody>
        <tr>
            <td class="code-outline">
            <pre class="displaycode"><br>$file_handle = fopen(&quot;myfile&quot;, &quot;r&quot;);<br>while (!feof($file_handle)) {<br>   $line = fgets($file_handle);<br>   echo $line;<br>}<br>fclose($file_handle);</pre>
            </td>
        </tr>
    </tbody>
</table>
<br>
<p>虽然大多数具有多年编程经验的程序员都熟悉这些函数，但是让我对这些函数进行分解。有效地执行以下步骤：</p>
<ol>
    <li>打开文件。<code>$file_handle</code> 存储了一个对文件本身的引用。</li>
    <li>检查您是否已到达文件的末尾。</li>
    <li>继续读取文件，直至到达文件末尾，边读取边打印每行。</li>
    <li>关闭文件。</li>
</ol>
<p>记住这些步骤，我将回顾在这里使用的每个文件函数。</p>
<p><a name="fopen"><span class="smalltitle">fopen</span></a></p>
<p><code>fopen</code> 函数将创建与文件的连接。我之所以说&ldquo;创建连接&rdquo;，是因为除了打开文件之外，<code>fopen</code> 还可以打开一个 URL：</p>
<table width="50%" cellspacing="0" cellpadding="0" border="0">
    <tbody>
        <tr>
            <td class="code-outline">
            <pre class="displaycode">$fh = fopen(&quot;http://127.0.0.1/&quot;, &quot;r&quot;);</pre>
            </td>
        </tr>
    </tbody>
</table>
<br>
<p>这行代码将创建一个与以上页面的连接，并允许您开始像读取一个本地文件一样读取它。</p>
<p><strong>注：</strong>     <code>fopen</code> 中使用的 <code>&quot;r&quot;</code> 将指示文件以只读方式打开。由于将数据写入文件不在本文的讨论范围内，因此我将不列出所有其他选项。但是，如果是从二进制文件读取以获得跨平台兼容性，则应当将 <code>&quot;r&quot;</code> 更改为 <code>&quot;rb&quot;</code>。稍后您将看到这样的示例。</p>
<p><a name="feof"><span class="smalltitle">feof</span></a></p>
<p><code>feof</code> 命令将检测您是否已经读到文件的末尾并返回 True 或 False。<a href="http://www.ibm.com/developerworks/cn/opensource/os-php-readfiles/index.html#list1">清单 1</a> 中的循环将继续执行，直至您达到文件&ldquo;myfile&rdquo;的末尾。注：如果读取的是 URL 并且套接字由于不再有任何数据可以读取而超时，则 <code>feof</code> 也将返回 False。</p>
<p><a name="fclose"><span class="smalltitle">fclose</span></a></p>
<p>向前跳至清单 1 的末尾，<code>fclose</code> 将实现与 <code>fopen</code> 相反的功能：它将关闭指向文件或 URL 的连接。执行此函数后，您将不再能够从文件或套接字中读取任何信息。</p>
<p><a name="fgets"><span class="smalltitle">fgets</span></a></p>
<p>在清单 1 中回跳几行，您就到达了文件处理的核心：实际读取文件。<code>fgets</code> 函数是处理第一个示例的首选武器。它将从文件中提取一行数据并将其作为字符串返回。在那之后，您可以打印或者以别的方式处理数据。清单 1 中的示例将精细地打印整个文件。</p>
<p>如果决定限制处理数据块的大小，您可以将一个参数添加到 <code>fgets</code> 中限制最大行长度。例如，使用以下代码将行长度限制为 80 个字符：</p>
<table width="50%" cellspacing="0" cellpadding="0" border="0">
    <tbody>
        <tr>
            <td class="code-outline">
            <pre class="displaycode">$string = fgets($file_handle, 81);</pre>
            </td>
        </tr>
    </tbody>
</table>
<br>
<p>回想 C 中的&ldquo;\0&rdquo;字符串末尾终止符，将长度设为比实际所需值大一的数字。因而，如果需要 80 个字符，则以上示例使用 81。应养成以下习惯：只要对此函数使用行限制，就添加该额外字符。</p>
<p><a name="fread"><span class="smalltitle">fread</span></a></p>
<p><code>fgets</code> 函数是多个文件读取函数中惟一一个可用的。它是一个更常用的函数，因为逐行解析通常会有意义。事实上，几个其他函数也可以提供类似功能。但是，您并非总是需要逐行解析。</p>
<p>这时就需要使用 <code>fread</code>。<code>fread</code> 函数与 <code>fgets</code> 的处理目标略有不同：它趋于从二进制文件（即，并非主要包含人类可阅读的文本的文件）中读取信息。由于&ldquo;行&rdquo;的概念与二进制文件无关（逻辑数据结构通常都不是由新行终止），因此您必须指定需要读入的字节数。</p>
<table width="50%" cellspacing="0" cellpadding="0" border="0">
    <tbody>
        <tr>
            <td class="code-outline">
            <pre class="displaycode">$fh = fopen(&quot;myfile&quot;, &quot;rb&quot;);<br>$data = fread($file_handle, 4096);</pre>
            </td>
        </tr>
    </tbody>
</table>
<br>
<table width="40%" cellspacing="0" cellpadding="0" border="0" align="right">
    <tbody>
        <tr>
            <td width="10"><img height="1" width="10" src="http://www.ibm.com/i/c.gif"></td>
            <td>
            <table width="100%" cellspacing="0" cellpadding="5" border="1">
                <tbody>
                    <tr>
                        <td bgcolor="#eeeeee"><a name="sidebar1"><strong>使用二进制数据</strong></a><br>
                        <p>注意：此函数的示例已经使用了略微不同于 <code>fopen</code> 的参数。当处理二进制数据时，始终要记得将 <code>b</code> 选项包含在 <code>fopen</code> 中。如果跳过这一点，Microsoft&#174; Windows&#174; 系统可能无法正确处理文件，因为它们将以不同的方式处理新行。如果处理的是 Linux&#174; 系统（或其他某个 UNIX&#174; 变种），则这可能看似没什么关系。但即使不是针对 Windows 开发的，这样做也将获得良好的跨平台可维护性，并且也是应当遵循的一个好习惯。</p>
                        </td>
                    </tr>
                </tbody>
            </table>
            </td>
        </tr>
    </tbody>
</table>
<p>以上代码将读取 4,096 字节 (4 KB) 的数据。注：不管指定多少字节，<code>fread</code> 都不会读取超过 8,192 个字节 (8 KB)。</p>
<p>假定文件大小不超过 8 KB，则以下代码应当能将整个文件读入一个字符串。</p>
<table width="50%" cellspacing="0" cellpadding="0" border="0">
    <tbody>
        <tr>
            <td class="code-outline">
            <pre class="displaycode">$fh = fopen(&quot;myfile&quot;, &quot;rb&quot;);<br>$data = fread($fh, filesize(&quot;myfile&quot;));<br>fclose($fh);</pre>
            </td>
        </tr>
    </tbody>
</table>
<br>
<p>如果文件长度大于此值，则只能使用循环将其余内容读入。</p>
<p><a name="fscanf"><span class="smalltitle">fscanf</span></a></p>
<p>回到字符串处理，<code>fscanf</code> 同样遵循传统的 C 文件库函数。如果您不熟悉它，则 <code>fscanf</code> 将把字段数据从文件读入变量中。</p>
<table width="50%" cellspacing="0" cellpadding="0" border="0">
    <tbody>
        <tr>
            <td class="code-outline">
            <pre class="displaycode">list ($field1, $field2, $field3) = fscanf($fh, &quot;%s %s %s&quot;);</pre>
            </td>
        </tr>
    </tbody>
</table>
<br>
<p>此函数使用的格式字符串在很多地方都有描述（如 PHP.net 中），故在此不再赘述。可以这样说，字符串格式化极为灵活。值得注意的是所有字段都放在函数的返回值中。（在 C 中，它们都被作为参数传递。）</p>
<p><a name="fgets"><span class="smalltitle">fgetss</span></a></p>
<p><code>fgetss</code> 函数不同于传统文件函数并使您能更好地了解 PHP 的力量。该函数的功能类似于 <code>fgets</code> 函数，但将去掉发现的任何 HTML 或 PHP 标记，只留下纯文本。查看如下所示的 HTML 文件。</p>
<br>
<a name="list2"><strong>清单 2. 样例 HTML 文件</strong></a><br>
<table width="50%" cellspacing="0" cellpadding="0" border="0">
    <tbody>
        <tr>
            <td class="code-outline">
            <pre class="displaycode"><br>&lt;html&gt;<br>    &lt;head&gt;&lt;title&gt;My title&lt;/title&gt;&lt;/head&gt;<br>    &lt;body&gt;<br>        &lt;p&gt;If you understand what &quot;Cause there ain't no one for to give you no pain&quot;<br>            means then you listen to too much of the band America&lt;/p&gt;<br>    &lt;/body&gt;<br>&lt;/html&gt;</pre>
            </td>
        </tr>
    </tbody>
</table>
<br>
<p>然后通过 <code>fgetss</code> 函数过滤它。</p>
<br>
<a name="list3"><strong>清单 3. 使用 fgetss</strong></a><br>
<table width="50%" cellspacing="0" cellpadding="0" border="0">
    <tbody>
        <tr>
            <td class="code-outline">
            <pre class="displaycode"><br>$file_handle = fopen(&quot;myfile&quot;, &quot;r&quot;);<br>while (!feof($file_handle)) {<br>   echo = fgetss($file_handle);<br>}<br>fclose($file_handle);</pre>
            </td>
        </tr>
    </tbody>
</table>
<br>
<p>以下是输出：</p>
<table width="50%" cellspacing="0" cellpadding="0" border="0">
    <tbody>
        <tr>
            <td class="code-outline">
            <pre class="displaycode">My title<br><br>        If you understand what &quot;Cause there ain't no one for to give you no pain&quot;<br>            means then you listen to too much of the band America</pre>
            </td>
        </tr>
    </tbody>
</table>
<br>
<p><a name="fpassthru"><span class="smalltitle">fpassthru 函数</span></a></p>
<p>无论怎样读取文件，您都可以使用 <code>fpassthru</code> 将其余数据转储到标准输出通道。</p>
<table width="50%" cellspacing="0" cellpadding="0" border="0">
    <tbody>
        <tr>
            <td class="code-outline">
            <pre class="displaycode">fpassthru($fh);</pre>
            </td>
        </tr>
    </tbody>
</table>
<br>
<p>此外，此函数将打印数据，因此无需使用变量获取数据。</p>
<p><a name="N101B6"><span class="atitle">非线性文件处理：跳跃访问</span></a></p>
<p>当然，以上函数只允许顺序读取文件。更复杂的文件可能要求您来回跳转到文件的不同部分。这时就用得着 <code>fseek</code> 了。</p>
<table width="50%" cellspacing="0" cellpadding="0" border="0">
    <tbody>
        <tr>
            <td class="code-outline">
            <pre class="displaycode">fseek($fh, 0);</pre>
            </td>
        </tr>
    </tbody>
</table>
<br>
<p>以上示例将跳转回文件的开头。如果不需要完全返回 &mdash;&mdash; 我们可设定返回千字节 &mdash;&mdash; 然后就可以这样写：</p>
<table width="50%" cellspacing="0" cellpadding="0" border="0">
    <tbody>
        <tr>
            <td class="code-outline">
            <pre class="displaycode">fseek($fh, 1024);</pre>
            </td>
        </tr>
    </tbody>
</table>
<br>
<p>从 PHP V4.0 开始，您有一些其他选项。例如，如果需要从当前位置向前跳转 100 个字节，则可以尝试使用：</p>
<table width="50%" cellspacing="0" cellpadding="0" border="0">
    <tbody>
        <tr>
            <td class="code-outline">
            <pre class="displaycode">fseek($fh, 100, SEEK_CUR);</pre>
            </td>
        </tr>
    </tbody>
</table>
<br>
<p>类似地，可以使用以下代码向后跳转 100 个字节：</p>
<table width="50%" cellspacing="0" cellpadding="0" border="0">
    <tbody>
        <tr>
            <td class="code-outline">
            <pre class="displaycode">fseek($fh, -100, SEEK_CUR);</pre>
            </td>
        </tr>
    </tbody>
</table>
<br>
<p>如果需要向后跳转至文件末尾前 100 个字节处，则应使用 <code>SEEK_END</code>。</p>
<table width="50%" cellspacing="0" cellpadding="0" border="0">
    <tbody>
        <tr>
            <td class="code-outline">
            <pre class="displaycode">fseek($fh, -100, SEEK_END);</pre>
            </td>
        </tr>
    </tbody>
</table>
<br>
<p>在到达新位置后，可以使用 <code>fgets</code>、<code>fscanf</code> 或任何其他方法读取数据。</p>
<p><strong>注：</strong>不能将 <code>fseek</code> 用于引用 URL 的文件处理。</p>
<br>
<table width="100%" cellspacing="0" cellpadding="0" border="0">
    <tbody>
        <tr>
            <td><img height="1" width="100%" src="http://www.ibm.com/i/v14/rules/blue_rule.gif"><br>
            <img height="6" width="8" border="0" src="http://www.ibm.com/i/c.gif"></td>
        </tr>
    </tbody>
</table>
<table cellspacing="0" cellpadding="0" align="right" class="no-print">
    <tbody>
        <tr align="right">
            <td><img height="4" width="100%" src="http://www.ibm.com/i/c.gif"><br>
            <table cellspacing="0" cellpadding="0" border="0">
                <tbody>
                    <tr>
                        <td valign="middle"> </td>
                        <td valign="top" align="right"><a href="http://www.ibm.com/developerworks/cn/opensource/os-php-readfiles/index.html#main" class="fbox"><strong><br>
                        </strong></a></td>
                    </tr>
                </tbody>
            </table>
            </td>
        </tr>
    </tbody>
</table>
<br>
<br>
<p><a name="N10201"><span class="atitle">提取整个文件</span></a></p>
<p>现在，我们将接触到一些 PHP 的更独特的文件处理功能：用一两行处理大块数据。例如，如何提取文件并在 Web 页面上显示其全部内容？好的，您看到了 <code>fgets</code> 使用循环的示例。但是如何能够使此过程变得更简单？用 <code>fgetcontents</code> 会使过程超级简单，该方法将把整个文件放入一个字符串中。</p>
<table width="50%" cellspacing="0" cellpadding="0" border="0">
    <tbody>
        <tr>
            <td class="code-outline">
            <pre class="displaycode">$my_file = file_get_contents(&quot;myfilename&quot;);<br>echo $my_file;</pre>
            </td>
        </tr>
    </tbody>
</table>
<br>
<p>虽然它不是最好的做法，但是可以将此命令更简明地写为：</p>
<table width="50%" cellspacing="0" cellpadding="0" border="0">
    <tbody>
        <tr>
            <td class="code-outline">
            <pre class="displaycode">echo file_get_contents(&quot;myfilename&quot;);</pre>
            </td>
        </tr>
    </tbody>
</table>
<br>
<p>本文主要介绍的是如何处理本地文件，但是值得注意的是您还可以用这些函数提取、回显和解析其他 Web 页面。</p>
<table width="50%" cellspacing="0" cellpadding="0" border="0">
    <tbody>
        <tr>
            <td class="code-outline">
            <pre class="displaycode">echo file_get_contents(&quot;http://127.0.0.1/&quot;);</pre>
            </td>
        </tr>
    </tbody>
</table>
<br>
<p>此命令等效于：</p>
<table width="50%" cellspacing="0" cellpadding="0" border="0">
    <tbody>
        <tr>
            <td class="code-outline">
            <pre class="displaycode">$fh = fopen(&quot;http://127.0.0.1/&quot;, &quot;r&quot;);<br>fpassthru($fh);</pre>
            </td>
        </tr>
    </tbody>
</table>
<br>
<p>您一定会查看此命令并认为：&ldquo;那还是太费力&rdquo;。PHP 开发人员同意您的看法。因此可以将以上命令缩短为：</p>
<table width="50%" cellspacing="0" cellpadding="0" border="0">
    <tbody>
        <tr>
            <td class="code-outline">
            <pre class="displaycode">readfile(&quot;http://127.0.0.1/&quot;);</pre>
            </td>
        </tr>
    </tbody>
</table>
<br>
<p><code>readfile</code> 函数将把文件或 Web 页面的全部内容转储到默认的输出缓冲区。默认情况下，如果失败，此命令将打印错误消息。要避免此行为（如果需要），请尝试：</p>
<table width="50%" cellspacing="0" cellpadding="0" border="0">
    <tbody>
        <tr>
            <td class="code-outline">
            <pre class="displaycode">@readfile(&quot;http://127.0.0.1/&quot;);</pre>
            </td>
        </tr>
    </tbody>
</table>
<br>
<p>当然，如果确实需要解析文件，则 <code>file_get_contents</code> 返回的单个字符串可能有些让人吃不消。您的第一反应可能是用 <code>split()</code> 函数将它分解一下。</p>
<table width="50%" cellspacing="0" cellpadding="0" border="0">
    <tbody>
        <tr>
            <td class="code-outline">
            <pre class="displaycode">$array = split(&quot;\n&quot;, file_get_contents(&quot;myfile&quot;));</pre>
            </td>
        </tr>
    </tbody>
</table>
<br>
<p>但是既然已经有一个很好的函数为您执行此操作为什么还要这样大费周章？PHP 的 <code>file()</code> 函数一步即可完成此操作：它将返回分为若干行的字符串数组。</p>
<table width="50%" cellspacing="0" cellpadding="0" border="0">
    <tbody>
        <tr>
            <td class="code-outline">
            <pre class="displaycode">$array = file(&quot;myfile&quot;);</pre>
            </td>
        </tr>
    </tbody>
</table>
<br>
<p>应当注意的是，以上两个示例有一点细微差别。虽然 <code>split</code> 命令将删除新行，但是当使用 <code>file</code> 命令（与 <code>fgets</code> 命令一样）时，新行仍将被附加到数组中的字符串上。</p>
<p>但是，PHP 的力量还远不止于此。您可以在一条命令中使用 <code>parse_ini_file</code> 解析整个 PHP 样式的 .ini 文件。<code>parse_ini_file</code> 命令接受类似清单 4 所示的文件。</p>
<br>
<a name="list4"><strong>清单 4. 样例 .ini 文件</strong></a><br>
<table width="50%" cellspacing="0" cellpadding="0" border="0">
    <tbody>
        <tr>
            <td class="code-outline">
            <pre class="displaycode"><br>; Comment<br>[personal information]<br>name = &quot;King Arthur&quot;<br>quest = To seek the holy grail<br>favorite color = Blue<br><br>[more stuff]<br>Samuel Clemens = Mark Twain<br>Caryn Johnson = Whoopi Goldberg</pre>
            </td>
        </tr>
    </tbody>
</table>
<br>
<p>以下命令将把此文件转储为数组，然后打印该数组：</p>
<table width="50%" cellspacing="0" cellpadding="0" border="0">
    <tbody>
        <tr>
            <td class="code-outline">
            <pre class="displaycode">$file_array = parse_ini_file(&quot;holy_grail.ini&quot;);<br>print_r $file_array;</pre>
            </td>
        </tr>
    </tbody>
</table>
<br>
<p>以下输出的是结果：</p>
<br>
<a name="list5"><strong>Listing 5. 输出</strong></a><br>
<table width="50%" cellspacing="0" cellpadding="0" border="0">
    <tbody>
        <tr>
            <td class="code-outline">
            <pre class="displaycode"><br>Array<br>(<br>    [name] =&gt; King Arthur<br>    [quest] =&gt; To seek the Holy Grail<br>    [favorite color] =&gt; Blue<br>    [Samuel Clemens] =&gt; Mark Twain<br>    [Caryn Johnson] =&gt; Whoopi Goldberg<br>)</pre>
            </td>
        </tr>
    </tbody>
</table>
<br>
<p>当然，您可能注意到此命令合并了各个部分。这是默认行为，但是您可以通过将第二个参数传递给 <code>parse_ini_file</code> 轻松地修正它：<code>process_sections</code>，这是一个布尔型变量。将 <code>process_sections</code> 设为 True。</p>
<table width="50%" cellspacing="0" cellpadding="0" border="0">
    <tbody>
        <tr>
            <td class="code-outline">
            <pre class="displaycode">$file_array = parse_ini_file(&quot;holy_grail.ini&quot;, true);<br>print_r $file_array;</pre>
            </td>
        </tr>
    </tbody>
</table>
<br>
<p>并且您将获得以下输出：</p>
<br>
<a name="list6"><strong>清单 6. 输出</strong></a><br>
<table width="50%" cellspacing="0" cellpadding="0" border="0">
    <tbody>
        <tr>
            <td class="code-outline">
            <pre class="displaycode"><br>Array<br>(<br>    [personal information] =&gt; Array<br>        (<br>            [name] =&gt; King Arthur<br>            [quest] =&gt; To seek the Holy Grail<br>            [favorite color] =&gt; Blue<br>        )<br><br>    [more stuff] =&gt; Array<br>        (<br>            [Samuel Clemens] =&gt; Mark Twain<br>            [Caryn Johnson] =&gt; Whoopi Goldberg<br>        )<br><br>)</pre>
            </td>
        </tr>
    </tbody>
</table>
<br>
<p>PHP 将把数据放入可以轻松解析的多维数组中。</p>
<p>对于 PHP 文件处理来说，这只是冰山一角。诸如 <code>tidy_parse_file</code> 和 <code>xml_parse</code> 之类的更复杂的函数可以分别帮助您处理 HTML 和 XML 文档。有关这些特殊函数的使用细节，请参阅 <a href="http://www.ibm.com/developerworks/cn/opensource/os-php-readfiles/index.html#resources">参考资料</a>。如果您要处理那些类型的文件，则那些参考资料值得一看，但不必过度考虑本文中谈到的每种可能遇到的文件类型，下面是一些用于处理到目前为止介绍的函数的很好的通用规则。</p>
<br>
<table width="100%" cellspacing="0" cellpadding="0" border="0">
    <tbody>
        <tr>
            <td><img height="1" width="100%" src="http://www.ibm.com/i/v14/rules/blue_rule.gif"><br>
            <img height="6" width="8" border="0" src="http://www.ibm.com/i/c.gif"></td>
        </tr>
    </tbody>
</table>
<table cellspacing="0" cellpadding="0" align="right" class="no-print">
    <tbody>
        <tr align="right">
            <td><img height="4" width="100%" src="http://www.ibm.com/i/c.gif"><br>
            <table cellspacing="0" cellpadding="0" border="0">
                <tbody>
                    <tr>
                        <td valign="middle"> </td>
                        <td valign="top" align="right"><a href="http://www.ibm.com/developerworks/cn/opensource/os-php-readfiles/index.html#main" class="fbox"><strong><br>
                        </strong></a></td>
                    </tr>
                </tbody>
            </table>
            </td>
        </tr>
    </tbody>
</table>
<br>
<br>
<p><a name="N102CB"><span class="atitle">最佳实践</span></a></p>
<p>绝不要假定程序中的一切都将按计划运行。例如，如果您要查找的文件已被移动该当如何？如果权限已被改变而无法读取其内容又当如何？您可以通过使用 <code>file_exists</code> 和 <code>is_readable</code> 预先检查这些问题。</p>
<br>
<a name="list7"><strong>清单 7. 使用 file_exists 和 is_readable</strong></a><br>
<table width="50%" cellspacing="0" cellpadding="0" border="0">
    <tbody>
        <tr>
            <td class="code-outline">
            <pre class="displaycode"><br>$filename = &quot;myfile&quot;;<br>if (file_exists($filename) &amp;&amp; <span class="boldcode">is_readable</span> ($filename)) {<br> $fh = fopen($filename, &quot;r&quot;);<br> # Processing<br> fclose($fh);<br>}</pre>
            </td>
        </tr>
    </tbody>
</table>
<br>
<p>但是，在实践中，用这样的代码可能太繁琐了。处理 <code>fopen</code> 的返回值更简单并且更准确。</p>
<table width="50%" cellspacing="0" cellpadding="0" border="0">
    <tbody>
        <tr>
            <td class="code-outline">
            <pre class="displaycode">if ($fh = fopen($filename, &quot;r&quot;)) {<br> # Processing<br> fclose($fh);<br>}</pre>
            </td>
        </tr>
    </tbody>
</table>
<br>
<p>由于失败时 <code>fopen</code> 将返回 False，这将确保仅当文件成功打开后才执行文件处理。当然，如果文件不存在或者不可读，您可以期望一个负返回值。这将使这个检查可以检查所有可能遇到的问题。此外，如果打开失败，可以退出程序或让程序显示错误消息。</p>
<p>如 <code>fopen</code> 函数一样，<code>file_get_contents</code>、<code>file</code> 和 <code>readfile</code> 函数都在打开失败或处理文件失败时返回 False。<code>fgets</code>、<code>fgetss</code>、<code>fread</code>、<code>fscanf</code> 和 <code>fclose</code> 函数在出错时也返回 False。当然，除 <code>fclose</code> 以外，您可能已经对这些函数的返回值都进行了处理。使用 <code>fclose</code> 时，即使文件处理未正常关闭，也不会执行什么操作，因此通常不必检查 <code>fclose</code> 的返回值。</p>
<br>
<table width="100%" cellspacing="0" cellpadding="0" border="0">
    <tbody>
        <tr>
            <td><img height="1" width="100%" src="http://www.ibm.com/i/v14/rules/blue_rule.gif"><br>
            <img height="6" width="8" border="0" src="http://www.ibm.com/i/c.gif"></td>
        </tr>
    </tbody>
</table>
<table cellspacing="0" cellpadding="0" align="right" class="no-print">
    <tbody>
        <tr align="right">
            <td><img height="4" width="100%" src="http://www.ibm.com/i/c.gif"><br>
            <table cellspacing="0" cellpadding="0" border="0">
                <tbody>
                    <tr>
                        <td valign="middle"> </td>
                        <td valign="top" align="right"><a href="http://www.ibm.com/developerworks/cn/opensource/os-php-readfiles/index.html#main" class="fbox"><strong><br>
                        </strong></a></td>
                    </tr>
                </tbody>
            </table>
            </td>
        </tr>
    </tbody>
</table>
<br>
<br>
<p><a name="N1032F"><span class="atitle">由您来选择</span></a></p>
<p>PHP 不缺读取和解析文件的有效方法。诸如 <code>fread</code> 之类的典型函数可能在大多数时候都是最佳的选择，或者当 <code>readfile</code> 刚好能满足任务需要时，您可能会发现自己更为 <code>readfile</code> 的简单所吸引。它实际上取决于所要完成的操作。</p>
<p>如果要处理大量数据，<code>fscanf</code> 将能证明自己的价值并比使用 <code>file</code> 附带 <code>split</code> 和 <code>sprintf</code> 命令更有效率。相反，如果要回显只做了少许修改的大量文本，则使用 <code>file</code>、<code>file_get_contents</code> 或 <code>readfile</code> 可能更合适。使用 PHP 进行缓存或者创建权宜的代理服务器时可能就属于这种情况。</p>
<p>PHP 给您提供了大量处理文件的工具。深入了解这些工具并了解哪些工具最适合于要处理的项目。您已拥有很多的选择，因此好好地利用它们享受使用 PHP 处理文件的乐趣。</p> 
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/lhbmqq/blog/category/Php">Php</a>&nbsp;<a href="http://hi.baidu.com/lhbmqq/blog/item/59ae1af7bcf87125730eec5b.html#comment">查看评论</a>]]></description>
        <pubDate>2009年02月17日 星期二  21:04</pubDate>
        <category><![CDATA[Php]]></category>
        <author><![CDATA[lhbmqq]]></author>
		<guid>http://hi.baidu.com/lhbmqq/blog/item/59ae1af7bcf87125730eec5b.html</guid>
</item>

<item>
        <title><![CDATA[Windows定时自动执行PHP程序]]></title>
        <link><![CDATA[http://hi.baidu.com/lhbmqq/blog/item/4e5792cbf32f5efa53664fed.html]]></link>
        <description><![CDATA[
		
		<p>作者：phpteam, ptker <br>
整理：21andy.com <br>
版权声明：可以任意转载，转载时请务必标明文章原始出处和作者信息及本声明</p>
<p>相信不少读者（PHP爱好者）在工作、学习的过程中经常抱怨：在WIN如何让PHP定时自动发信呢？？如何让MYSQL实现自动备份而无后顾之忧 呢？？如 果完全依靠手工进行当然也可以实现，但操作上似乎过于繁琐了一点！别着急，利用系统的任务计划程序(Windows 98称之为计划任务)可轻易解决这一问题。这一功能往往被很多用户忽略或者未曾想到：）。</p>
<p>所谓任务计划就是由计算机自动调用用户事先设置好的应用程序，从而达到简化用户操作的目的。利用Windows 2000的任务计划程序（相当与*NIX下的cron程序，这里不再对其详述），我们可以安排任何脚本、程序或文档在最恰当的时候运行，从而满足自己的需 要。下面以Windows 2000为例。</p>
<p>具体来说，我们若需利用任务计划程序自动运行则应执行如下步骤：</p>
<ol>
    <li>单击&quot;开始&quot;按钮，然后依次选择&quot;程序&quot;→&quot;附件&quot;→&quot;系统工具&quot;→&quot;任务计划&quot;（或者是&quot;设置&quot;→&quot;控制面板&quot;→&quot;任务计划&quot;），启动Windows 2000的任务计划管理程序。</li>
    <li>在&quot;任务计划&quot;窗口中双击&quot;添加任务计划&quot;图标，启动系统的&quot;任务计划向导&quot;，然后单击&quot;下一步&quot;按钮，在给出的程序列表中选择需要自动运行的应用程序，然后单击&quot;下一步&quot;按钮。</li>
    <li>设置适当的任务计划名称并选择自动执行这个任务的时间频率(如每天、每星期、每月、一次性、每次启动计算机时、每次登录时等)，然后单击&quot;下一 步&quot;按钮。此时系统将会要求用户对程序运行的具体时间进行设置，如几号、几点钟、哪几个时间段才能运行等，我们只需根据自己的需要加以设置即可。</li>
    <li>接下来系统将会要求用户设置适当的用户名及密码(如图5所示)，以便系统今后能自动加以运行。</li>
    <li>最后，我们只需单击&quot;完成&quot;按钮即可将相应任务添加到Windows 2000的任务计划程序中，此后它就会自动&quot;记住&quot;这个任务，一旦系统时间及相关条件与用户设置的计划相符，它就会自动调用用户所指定的应用程序，十分方 便(每次启动Windows 2000的时候，任务计划程序都会自动启动，并在后台运行，确保用户的计划能够按时执行)。</li>
</ol>
<p>现在我们来测试一下刚才所建的任务是否成功，鼠标右键单击&quot;php&quot;程序图标(如图6所示)，在弹出的菜单里面选择&quot;运行&quot;。一般情况下程序图标只 要这样 激活运行就可以正常启动。如果运行失败可查看用户和密码是否设置正确，还有确定&quot;Task Scheduler&quot;服务是否已启动，本人当初就是为了节省系统资源把它关掉了导致运行失败，害我找了大半天。另外也可从&quot;系统日志&quot;里查看到底是什么原 因造成运行失败的。</p>
<p>好了，讲了这么多任务计划的应用，现在我们切入正题，下面将介绍两个例子：</p>
<p><strong>一、让PHP定时运行</strong></p>
<ol>
    <li>编辑如下代码，并保存为test.php： <br>
    <br>
    <blockquote>
    <p>&lt;?php <br>
    $fp = @fopen(&quot;test.txt&quot;, &quot;a+&quot;); <br>
    fwrite($fp, date(&quot;Y-m-d H:i:s&quot;) . &quot; 让PHP定时运行吧！\n&quot;); <br>
    fclose($fp); <br>
    ?&gt;</p>
    </blockquote></li>
    <li>添加一个任务计划，在(如图2所示)这一步输入命令： <br>
    <br>
    <blockquote>
    <p>D:\php4\php.exe -q D:\php4\test.php</p>
    </blockquote></li>
    <li>时间设置为每隔1分钟运行一次，然后运行这个任务。</li>
    <li>现在我们来看看d:\php4\test.txt文件的内容时候是否成功。如果内容为如下所示，那么恭喜你成功了。 <br>
    <br>
    <blockquote>
    <p>2003-03-03 11:08:01 让PHP定时运行吧！ <br>
    2003-03-03 11:09:02 让PHP定时运行吧！ <br>
    2003-03-03 11:10:01 让PHP定时运行吧！ <br>
    2003-03-03 11:11:02 让PHP定时运行吧！</p>
    </blockquote></li>
</ol>
<p><strong>二、让MYSQL实现自动备份</strong></p>
<ol>
    <li>编辑如下代码，并保存为backup.php，如果要压缩可以拷贝一个rar.exe： <br>
    <br>
    <blockquote>
    <p>&lt;?php <br>
    if ($argc != 2 || in_array($argv[1], array('--help', '-?'))) { <br>
    ?&gt; <br>
    backup Ver 0.01, for Win95/Win98/WinNT/Win2000/WinXP on i32 <br>
    Copyright (C) 2000 ptker All rights reserved. <br>
    This is free software,and you are welcome to modify and redistribute it <br>
    under the GPL license <br>
    <br>
    PHP Shell script for the backup MySQL database. <br>
    <br>
    Usage: &lt;?php echo $argv[0]; ?&gt; &lt;option&gt; <br>
    <br>
    &lt;option&gt; can be database name you would like to backup. <br>
    With the --help, or -? options, you can get this help and exit. <br>
    &lt;?php <br>
    } else { <br>
    $dbname = $argv[1]; <br>
    $dump_tool = &quot;c:\\mysql\\bin\\mysqldump&quot;; <br>
    $rar_tool = &quot;d:\\php4\\rar&quot;; <br>
    @exec(&quot;$dump_tool --opt -u user -ppassword $dbname &gt; ./$dbname.sql&quot;); <br>
    @exec(&quot;$rar_tool a -ag_yyyy_mm_dd_hh_mm $dbname.rar $dbname.sql&quot;); <br>
    @unlink(&quot;$dbname.sql&quot;); <br>
    echo &quot;Backup complete!&quot;; <br>
    } <br>
    ?&gt;</p>
    </blockquote></li>
    <li>添加一个任务计划，在(如图2所示)这一步输入命令： <br>
    <br>
    <blockquote>
    <p>D:\php4\php.exe -q D:\php4\backup.php databasename</p>
    </blockquote></li>
    <li>时间设置为每天运行一次，然后运行这个任务。</li>
    <li>最后会在d:\php4\目录下生成一个以数据库名和当前时间组成的rar文件。</li>
    <li>恭喜你！大功告成了！</li>
</ol>
<p>当然备份方式有很多种，读者可按照自己喜欢的去做！</p>
<p>以上是原著.结合本人实贱,补充说明如下:</p>
<ol>
    <li>如果出现错误: <br>
    <br>
    <blockquote>
    <p>在试着设置任务帐户信息时出现错误 <br>
    指定的错误是： <br>
    0x80070005:拒绝访问 <br>
    您没有运行所请求的操作的权限</p>
    </blockquote>
    <p>在上面'&quot;4.接下来系统将会要求用户设置适当的用户名及密码，以便系统今后能自动加以运行&quot;.这里最好用&quot;system&quot;用户,密码可为空. <br>
    这个system的权限非常之高,比你的administrator还要高,所以你在运行命令的时候千万不要乱来,这个可是什么提示都没有就会无条件执行的,这个权限下你kill核心进程都行.</p>
    </li>
    <li>上面2、添加一个任务计划，在这一步输入命令： <br>
    <br>
    <blockquote>
    <p>D:\php4\php.exe -q D:\php4\test.php</p>
    </blockquote>
    <p>正确形式应为</p>
    <blockquote>
    <p>&quot;D:\php4\php.exe&quot; -q &quot;D:\php4\test.php&quot;</p>
    </blockquote>
    <p>即路径要用双引号括住.</p>
    </li>
</ol> 
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/lhbmqq/blog/category/Php">Php</a>&nbsp;<a href="http://hi.baidu.com/lhbmqq/blog/item/4e5792cbf32f5efa53664fed.html#comment">查看评论</a>]]></description>
        <pubDate>2009年02月17日 星期二  15:56</pubDate>
        <category><![CDATA[Php]]></category>
        <author><![CDATA[lhbmqq]]></author>
		<guid>http://hi.baidu.com/lhbmqq/blog/item/4e5792cbf32f5efa53664fed.html</guid>
</item>


</channel>
</rss>