码迷,mamicode.com
首页 > Web开发 > 详细

php最简单的文件处理。

时间:2015-12-31 00:06:47      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:

 1 <?php 
 2    $DOCUMENT_ROOT =$_SERVER[‘DOCUMENT_ROOT‘];
 3 ?>
 4 
 5 <html>
 6 <head>
 7    <title>Bob‘s Auto Parts -Customer Orders </title>
 8 </head>
 9 <body>
10 <h1>Bob‘s Auto Parts</h1>
11 <h2>Customer Orders</h2>
12 
13 <?php
14   /*
15   $a=56;
16  if(!is_double ($a))    //测试is_int、is_double 、函数
17      echo "<p><strong>isn‘t double</strong ></p>";
18  echo gettype($a).‘<br/>‘;
19  settype($a,‘double‘);
20  echo gettype($a).‘<br/>‘;
21  */
22  
23   @$fp =fopen("$DOCUMENT_ROOT/orders/orders.txt",‘rb‘);
24   if (!$fp){
25   echo"<p><strong>No orders pending.
26        please try again later.</strong></p>";
27   exit ;
28   }
29 
30   /*
31   isset ();
32   
33   empty()
34   
35   */
36   //读取每行
37   while (!feof($fp)){
38       $order = fgets($fp,1024); //fgets()每次读取一行,遇到\n 、eof 、或者是998b结束。默认1k=1024b
39       echo $order."<br/>";     //fgetss() 和fgets()一样的功能,但是能过滤掉包含php和html的标记
40      }                         //fgetss(resource fp,int length,string[allowable_tags]) 把不过滤的标记放在allowable_tags中
41                                //$order = fgetss($fp,999,"<p>,<br/>");
42                                //  fgetcsv($fp,1024,"\t")  意思是遇到换行
43                                
44 /*
45 读取整个文件,
46 readfile("$DOCUMENT_ROOT/orders/orders.txt");
47 fpassthru($fp) ; //fp是一个指针
48 $filearray =file("$DOCUMENT_ROOT/orders/orders.txt") 
49 //功能和readfile一样,但是每一行是字符串数组的一个元素
50 */    
51 
52 /*
53 通过字符来输出整个文件
54 while(!feof($fp))
55     $char =fgetc($fp);
56   if(!feof($fp))
57       echo ($char =="\n"?<br/>:$char);                           
58 */                               
59 // fread($fp,int length)  读取任意长度,或者到eof    
60 
61 /*
62 file_exists("$DOCUMENT_ROOT/orders/orders.txt");
63 filesize();
64 unlink("$DOCUMENT_ROOT/orders/orders.txt")  //删除一个文件
65 
66 rewind($fp); //重新跳到开始指针
67 fseek ($fp);  //找到位置  字节数
68 ftell ($fp);  //显示出位置
69 
70 
71 */               
72                                
73 ?>
74 </body>  

 

php最简单的文件处理。

标签:

原文地址:http://www.cnblogs.com/biyongyao/p/5090260.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!