php最简单的文件处理。

WBOY
Release: 2016-06-20 12:41:40
Original
1017 people have browsed it

 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 <?php14   /*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=1024b39       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>  
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!