| 订阅 | 在线投稿
分享
 
 
 

初学者学习PHP开发应该掌握的几段精华代码

2008-12-28 07:39:25 编辑來源:互联网 国际版 评论
 
 
本文为【初学者学习PHP开发应该掌握的几段精华代码】的汉字拼音对照版显示拼音
  jingdianxunhuanlizi

  <HTML>

  <HEAD>

  <TITLE>jingdianxunhuanlizi</TITLE>

  </HEAD>

  <BODY>

  <?

   for($counter = 1; $counter <= 6; $counter++) //xunhuan6ci

   {

   print("<B>counter is $counter</B><BR>\n"); //dayin6ci

   }

  ?>

  </BODY>

  </HTML>

  fordegaojiyunyong

  <HTML>

  <HEAD>

  <TITLE>fordegaojiyunyong</TITLE>

  </HEAD>

  <BODY>

  <?

   /*

   ** dayinbiyaodeshuomingwenzi

   */

   print("<B>julixingqiyihuanyoujitian</B>\n");

   print("<OL>\n");

   for($currentDate = date("U"); //dingyi$currentDateshijiangeshi

   date("l", $currentDate) != "Monday"; //panduanshibushidangqianxitongshijianshiMonday

   $currentDate += (60 * 60 * 24)) //dangqianshijianjiashang1tian

   {

   /*

   ** dayinshijianmingcheng

   */

   print("<LI>" . date("l", $currentDate) . "\n");

   }

   print("</OL>\n");

  ?>

  </BODY>

  </HTML>

  hanshudejiandantiaoyong:

  <HTML>

  <HEAD>

  <TITLE>jiandandehanshu</TITLE>

  </HEAD>

  <BODY>

  <FONT SIZE=5>

  <?

   function printBold($inputText) //dingyifunction printBold

   {

   print("<B>" . $inputText . "</B>"); ////dayin$inputText

   }

   print("zhexingmeiyoujiachong<BR>\n"); //zhijiedayinzifuchuan

   printBold("zhexingjiachongle"); //tiaoyongfunction printBold()hanshu

   print("<BR>\n");

   print("zhexingmeiyoujiachong<BR>\n"); //zhijiedayinzifuchuan

  ?>

  </FONT>

  </BODY>

  </HTML>

  youfanhuizhidehanshu

  <HTML>

  <HEAD>

  <TITLE>youfanhuizhidehanshu</TITLE>

  </HEAD>

  <BODY>

  <FONT SIZE=5>

  <?

   function makeBold($inputText) //dingyifunction makeBold()hanshu

   {

   $boldedText = "<B>";

   $boldedText .= $inputText;

   $boldedText .= "</B>";

   return($boldedText); //fanhuibianliang$boldedText

   }

   print("zhexingmeiyoujiachong<BR>\n"); //zhijiedayinzifuchuan

   print(makeBold("zhexingbeijiachongle") . "<BR>\n");//tiaoyongfunction makeBold()hanshu

   print("zhexingmeiyoujiachong<BR>\n"); //zhijiedayinzifuchuan

  ?>

  </SIZE>

  </BODY>

  </HTML>

  youmorenshenshudehanshu

  <HTML>

  <HEAD>

  <TITLE>youmorenshenshudehanshu</TITLE>

  </HEAD>

  <BODY>

  <FONT SIZE=5>

  <?

   function printColored($Text, $Color="black") //dingyifunctionhanshu

   {

   print("<FONT COLOR=\"$Color\">$Text</FONT>"); //huoquzifuchuandeneirongheyanse

   }

   printColored("zheshiheiyansedezi"); //tiaoyongfunctionhanshu

   print("<BR><BR>\n");

   printColored("zheshilanyansedezi", "blue"); //tiaoyongfunctionhanshu

   print("<BR>\n");

  ?>

  </SIZE>

  </BODY>

  </HTML>

  yongdeguisuanfapanduanshifoushizhengshu

  <HTML>

  <HEAD>

  <TITLE>panduanzhengshu</TITLE>

  </HEAD>

  <BODY>

  <?

   function checkInteger($Number)

   {

   if($Number > 1)

   {

   /* zhengshujian1rengranshizhengshu */

   return(checkInteger($Number-1));

   }

   elseif($Number < 0)

   {

   /* duiyuyigefushu*/

   /* keyifenxitadejueduizhi*/

   return(checkInteger((-1)*$Number-1));//qujueduizhibafushuanzhengshufenxi

   }

   else

   {

   if(($Number > 0) AND ($Number < 1))

   {

   return("dangranbushi");

   }

   else

   {

   /* 0 he 1 shizhengshu */

   /* genjuxiangguanshuxuedingyi */

   return("shide");

   }

   }

   }

   print("<B>0shizhengshuma</B>" .

   checkInteger(0) . "<BR>\n");

   print("<B>7shizhengshuma</B> " .

   checkInteger(7) . "<BR>\n");

   print("<B>3.5ne</B>" . checkInteger(3.5) . "<BR>\n");

   print("<B>name-5ne</B>" . checkInteger(-5) . "<BR>\n");

   print("<B>huanyou-9.2</B>" . checkInteger(-9.2) . "<BR>\n");

  ?>

  </BODY>

  </HTML>

  chushihuashuzu

  <HTML>

  <HEAD>

  <TITLE>chushihuashuzu</TITLE>

  </HEAD>

  <FONT SIZE=5>

  <?

   $monthName = array(1=>"January", "February", "March",//chushihuayigeshuzu

   "April", "May", "June", "July", "August",

   "September", "October", "November", "December");

   print(" yingyude5yueshi<B> $monthName[5] </B><BR>\n");//dayinshuzuzhongdedi6geyuansu

  ?>

  </FONT>

  </BODY>

  </HTML>

  huoqushuzuzhongdeyuansu

  <HTML>

  <HEAD>

  <TITLE>huoqushuzuzhongdeyuansu</TITLE>

  </HEAD>

  <?

   $monthName = array(

   /*dingyi$monthName[1]dao$monthName[12]*/

   1=>"January", "February", "March",

   "April", "May", "June",

   "July", "August", "September",

   "October", "November", "December",

   /*dingyi$monthName["Jan"]dao$monthName["Dec"]*/

   "Jan"=>"January", "Feb"=>"February",

   "Mar"=>"March", "Apr"=>"April",

   "May"=>"May", "Jun"=>"June",

   "Jul"=>"July", "Aug"=>"August",

   "Sep"=>"September", "Oct"=>"October",

   "Nov"=>"November", "Dec"=>"December",

   /*dingyi$monthName["Jan"]dao$monthName["Dec"]*/

   "January"=>"January", "February"=>"February",

   "March"=>"March", "April"=>"April",

   "May"=>"May", "June"=>"June",

   "July"=>"July", "August"=>"August",

   "September"=>"September", "October"=>"October",

   "November"=>"November", "December"=>"December"

   );

   /*dayinxiangguandeyuansu*/

   print("Month <B>5</B> is <B>" . $monthName[5]. "</B><BR>\n");

   print("Month <B>Aug</B> is <B>" . $monthName["Aug"] . "</B><BR>\n");

   print("Month <B>June</B> is <B>" . $monthName["June"] . "</B><BR>\n");

  ?>

  </BODY>

  </HTML>

  chuangjianyigeduoweishuzu

  <HTML>

  <HEAD>

  <TITLE>chuangjianyigeduoweishuzu</TITLE>

  </HEAD>

  <?

   $Cities = array( //erweishuzuarray

   "huabeidiqu"=>array(

   "beijingshi",

   "tianjinshi",

   "shijiazhuang"

   ),

   "西xibeidiqu"=>array(

   "西xian",

   "lasa"

   )

   );

   print("huabeidiqu: ".$Cities["huabeidiqu"][0]); //dayin$Cities["huabeidiqu"][0]

  ?>

  </BODY>

  </HTML>

  PHP 4.0shixianbiaogezhuangdayin

  <HTML>

  <HEAD>

  <TITLE>shixianbiaogezhuangdayin</TITLE>

  </HEAD>

  <BODY>

  <?

   /*

   ** shujubiaogehua

   */

   print("<TABLE bgcolor='ffccoo' BORDER=\"1\">\n"); // biaogekaishi

  

   for($Row=1; $Row <= 12; $Row ++)

   {

   print("<TR>\n"); // kaishixing

   // do each column

   for($Column=1; $Column <= 12; $Column ++)

   {

   print("<TD>");//kaishilie

   print($Row * $Column);//biaogeyuansuchengji

   print("</TD>");

   }

   print("</TR>\n"); // xingjieshu

   }

  

   print("</TABLE>\n"); // biaogejieshu

  ?>

  </BODY>

  </HTML>

  chakanxitongdeyixiebianliang

  <HTML>

  <HEAD>

  <TITLE>chakanPHPdehuanjingbianliang</TITLE>

  </HEAD>

  <BODY>

  <?

   print("nizhengzaiyongwenjiandemingziwei ");

   print(__FILE__);

   print(" <BR>\n");

   print("<hr>");

   print("nidecaozuoxitongwei ");

   print(PHP_OS);

   print("<hr>");

   print("nidephpdebanbenwei ");

   print(PHP_VERSION)

  ?>

  </BODY>

  </HTML>

  dakaibendihuozheyuanchengwenjian

  <HTML>

  <HEAD>

  <TITLE>dakaibendihuozheyuanchengwenjian</TITLE>

  </HEAD>

  <BODY>

  <?

   print("<H3>tongguohttpxieyidakaiwenjian</H3>\n");

   // tongguo http xieyidakaiwenjian

   if(!($myFile = fopen("d:web/web/php/test/data.txt", "r")))

   {

   print("wenjianbunengdakai");

   exit;

   }

   while(!feof($myFile)) //xunhuan

   {

   // anxingduquwenjianzhongdeneirong

   $myLine = fgetss($myFile, 255);

   print("$myLine <BR>\n");

   }

   // guanbiwenjiandejubing

   fclose($myFile);

  ?>

  </BODY>

  </HTML>

  dakaiwenjiandejizhongfangshibijiao

  <HTML>

  <HEAD>

  <TITLE>duquwenjianneirong</TITLE>

  </HEAD>

  <BODY>

  <?

   // dakaiwenjiantongshidayinwenjiandemeiyigezifu

   if($myFile = fopen("data.txt", "r"))

   {

   while(!feof($myFile))

   {

   $myCharacter = fgetc($myFile);

   print($myCharacter);

   }

   fclose($myFile);

   }

  ?>

  <? print("<hr>");?>

  <?

   // dakaiwenjiantongshidayinwenjiandemeiyixing

   if($myFile = fopen("data.txt", "r"))

   {

   while(!feof($myFile))

   {

   $myLine = fgets($myFile, 255);

   print($myLine);

   }

   fclose($myFile);

   }

  ?>

  <? print("<hr>");?>

  <?

   /* dakaiwenjiantongshidayinwenjiandemeiyixing,

   tongshiqudiaoquhuizifuchuanzhongde HTML yuyan

   */

   if($myFile = fopen("data.txt", "r"))

   {

   while(!feof($myFile))

   {

   $myLine = fgetss($myFile, 255);

   print($myLine);

   }

   fclose($myFile);

   }

  ?>

  </BODY>

  </HTML>

  访fangwenwenjianchangjianshuxing

  <HTML>

  <HEAD>

  <TITLE>访fangwenwenjianchangjianshuxing</TITLE>

  </HEAD>

  <BODY>

  <BR>

  <?

   print("wenjiandesuoyouzheUID zhi");

   print(fileowner("data.txt")."<br>");

   print("wenjiandedaxiao");

   print(filesize("data.txt")."<br>");

   print("wenjiandeleixing");

   print(filetype("data.txt")."<br>");

  ?>

  </BODY>

  </HTML>

  tiaoyongwenbenwenjianneirong

  <HTML>

  <HEAD>

  <TITLE>tiaoyongwenbenwenjianneirong</TITLE>

  </HEAD>

  <BODY>

  <CENTER>

  <?

   // dakaiwenjiantongshidayinmeiyixing

   $myFile = file( "data.txt");

   for($index = 0; $index < count($myFile); $index++)

   {

   print($myFile[$index]."<BR>");

   }

  ?>

  </CENTER>

  </BODY>

  </HTML>

  chuangjianmuluhanshu

  <HTML>

  <HEAD>

  <TITLE>chuangjianmuluhanshu</TITLE>

  </HEAD>

  <BODY>

  <?

   if(mkdir("myDir1", 0777)) //chuangjianmuludehanshu

   {

   print("muluchuangjianchenggong"); //mulujianlichenggong

   }

   else

   {

   print("mulujianlishibai!"); //mulujianlishibai

   }

  ?>

  </BODY>

  </HTML>

  liulanmulu

  <HTML>

  <HEAD>

  <TITLE>liulanmulu</TITLE>

  </HEAD>

  <BODY>

  <?

   // 使shiyongbiaogeliulanmuludejiegou

   print("<TABLE BORDER=\"1\">\n");

   // chuangjianbiaogedetou

   print("<TR><font color='red'>\n");

   print("<TH>wenjianming</TH>\n");

   print("<TH>wenjiandedaxiao</TH>\n");

   print("</font></TR>\n");

   $myDirectory = opendir("."); // jianlicaozuomuludejubing

   // duchumuluzhongdemeiyigezixiang

   while($entryName = readdir($myDirectory))

   {

   print("<TR>");

   print("<TD>$entryName</TD>");

   print("<TD ALIGN=\"right\">");

   print(filesize($entryName));

   print("</TD>");

   print("</TR>\n");

   }

   closedir($myDirectory); // guanbimulu

   print("</TABLE>\n");

  ?>

  </BODY>

  </HTML>

  PHPxiangguanxinxi

  <HTML>

  <HEAD>

  <TITLE>PHPxiangguanxinxi</TITLE>

  </HEAD>

  <BODY>

  <?

   phpinfo();

  ?>

  </BODY>

  </HTML>

  changyongdeshuzhipanduanhanshu

  <HTML>

  <HEAD>

  <TITLE>changyongdeshuzhipanduanhanshu</TITLE>

  </HEAD>

  <BODY>

  <?

   //panduanshuzu

   $colors = array("red", "blue", "green");

   if(is_array($colors))

   {

   print("colors is an array"."<br>");

   }

   //shuangjingdushupanduan

   $Temperature = 15.23;

   if(is_double($Temperature))

   {

   print("Temperature is a double"."<br>");

   }

   //zhengshupanduan

   $PageCount = 2234;

   if(is_integer($PageCount))

   {

   print("$PageCount is an integer"."<br>");

   }

   //duixiangpanduan

   class widget

   {

   var $name;

   var $length;

   }

   $thing = new widget;

   if(is_object($thing))

   {

   print("thing is an object"."<br>");

   }

   //zifupanduan

   $Greeting = "Hello";

   if(is_string($Greeting))

   {

   print("Greeting is a string"."<br>");

   }

  ?>

  </BODY>

  </HTML>

  wenjianshangchuanjiemian

  <HTML>

  <HEAD>

  <TITLE>wenjianshangchuanjiemian</TITLE>

  </HEAD>

  <BODY><TABLE><CENTER>

  <?

  if($UploadAction){

  $UploadAction=0;

  $TimeLimit=60;

  /*shezhichaoshixianzhishijianmorenshijianwei 30sshezhiwei0shiweibuxianshi */

  set_time_limit($TimeLimit);

  If(($Upfile != "none")&&

  ($Upfile != ""))

  {

  $Filepath="d:\web\web\php\test"; //shangzaiwenjiancunfanglujing

  $FileName=$Filepath.$Upfile_name;

  if($Upfile_size <1024) //shangzaiwenjiandaxiao

  {$FileSize = (string)$Upfile_size . "zijie";}

  elseif($Upfile_size <(1024 * 1024))

  {

  $FileSize = number_format((double)($Upfile_size / 1024), 1) . " KB";

  }

  else

  {

  $FileSize = number_format((double)($Upfile_size/(1024*1024)),1)."MB";

  }

  if(!file_exists($FileName))

  {

  if(copy($Upfile,$FileName))

  {unlink($Upfile);

  echo "<br><br>\n";

  echo "wenjian $Upfile_name yishangzaichenggong";

  echo "<br><br>\n";

  echo "wenjianweizhi$FileName";

  echo "<br><br>\n";

  echo "wenjiandaxiao$FileSize";

  echo "<br><br>\n";

  }

  else

  {echo "wenjian $Upfile_nameshangzaishibai"; }

  }

  else

  {echo "wenjian $Upfile_nameyijingcunzai"; }

  }

  else

  {echo "nimeiyouxuanzerenhewenjianshangzai"; }

  set_time_limit(30); //huifumorenchaoshishezhi

  }

  ?>

  <FORM ENCTYPE = "multipart/form-data" NAME = "SubmitForm"

  ACTION = "default.php" METHOD = "POST">

  <INPUT TYPE = "hidden" NAME = "MAX_FILE_SIZE" VALUE ="1000000">

  <INPUT TYPE = "hidden" NAME = "UploadAction" VALUE = "1">

  <TR><TD><INPUT NAME = "Upfile" TYPE = "file" SIZE = "30"></TD>

  </TR><TR><TD><INPUT NAME = "submit" VALUE = "tijiao" TYPE = "submit">

  <INPUT NAME = "reset" VALUE = "chongzhi" TYPE = "reset"></TD>

  </TR></FORM></CENTER></TABLE>

  </BODY>

  </HTML>原文
 
 
经典循环例子 <HTML> <HEAD> <TITLE>经典循环例子</TITLE> </HEAD> <BODY> <? for($counter = 1; $counter <= 6; $counter++) //循环6次 { print("<B>counter is $counter</B><BR>\n"); //打印6次 } ?> </BODY> </HTML> for的高级运用 <HTML> <HEAD> <TITLE>for的高级运用</TITLE> </HEAD> <BODY> <? /* ** 打印必要的说明文字 */ print("<B>距离星期一还有几天?</B>\n"); print("<OL>\n"); for($currentDate = date("U"); //定义$currentDate时间格式 date("l", $currentDate) != "Monday"; //判断是不是当前系统时间是Monday $currentDate += (60 * 60 * 24)) //当前时间加上1天 { /* ** 打印时间名称 */ print("<LI>" . date("l", $currentDate) . "\n"); } print("</OL>\n"); ?> </BODY> </HTML> 函数的简单调用: <HTML> <HEAD> <TITLE>简单的函数</TITLE> </HEAD> <BODY> <FONT SIZE=5> <? function printBold($inputText) //定义function printBold() { print("<B>" . $inputText . "</B>"); ////打印$inputText } print("这行没有加重!<BR>\n"); //直接打印字符串 printBold("这行加重了!!!"); //调用function printBold()函数 print("<BR>\n"); print("这行没有加重!<BR>\n"); //直接打印字符串 ?> </FONT> </BODY> </HTML> 有返回值的函数 <HTML> <HEAD> <TITLE>有返回值的函数</TITLE> </HEAD> <BODY> <FONT SIZE=5> <? function makeBold($inputText) //定义function makeBold()函数 { $boldedText = "<B>"; $boldedText .= $inputText; $boldedText .= "</B>"; return($boldedText); //返回变量$boldedText } print("这行没有加重!!!<BR>\n"); //直接打印字符串 print(makeBold("这行被加重了!!!") . "<BR>\n");//调用function makeBold()函数 print("这行没有加重!!!<BR>\n"); //直接打印字符串 ?> </SIZE> </BODY> </HTML> 有默认参数的函数 <HTML> <HEAD> <TITLE>有默认参数的函数</TITLE> </HEAD> <BODY> <FONT SIZE=5> <? function printColored($Text, $Color="black") //定义function函数 { print("<FONT COLOR=\"$Color\">$Text</FONT>"); //获取字符串的内容和颜色 } printColored("这是黑颜色的字!"); //调用function函数 print("<BR><BR>\n"); printColored("这是蓝颜色的字!", "blue"); //调用function函数 print("<BR>\n"); ?> </SIZE> </BODY> </HTML> 用的规算法判断是否是整数 <HTML> <HEAD> <TITLE>判断整数</TITLE> </HEAD> <BODY> <? function checkInteger($Number) { if($Number > 1) { /* 整数减1仍然是整数 */ return(checkInteger($Number-1)); } elseif($Number < 0) { /* 对于一个负数,*/ /* 可以分析它的绝对值*/ return(checkInteger((-1)*$Number-1));//取绝对值,把负数按整数分析 } else { if(($Number > 0) AND ($Number < 1)) { return("当然不是"); } else { /* 0 和 1 是整数 */ /* 根据相关数学定义 */ return("是的"); } } } print("<B>0是整数吗?</B>" . checkInteger(0) . "<BR>\n"); print("<B>7是整数吗?</B> " . checkInteger(7) . "<BR>\n"); print("<B>3.5呢?</B>" . checkInteger(3.5) . "<BR>\n"); print("<B>那么-5呢?</B>" . checkInteger(-5) . "<BR>\n"); print("<B>还有-9.2?</B>" . checkInteger(-9.2) . "<BR>\n"); ?> </BODY> </HTML> 初始化数组 <HTML> <HEAD> <TITLE>初始化数组</TITLE> </HEAD> <FONT SIZE=5> <? $monthName = array(1=>"January", "February", "March",//初始化一个数组 "April", "May", "June", "July", "August", "September", "October", "November", "December"); print(" 英语的“5月”是<B> $monthName[5] </B>。<BR>\n");//打印数组中的第6个元素 ?> </FONT> </BODY> </HTML> 获取数组中的元素 <HTML> <HEAD> <TITLE>获取数组中的元素</TITLE> </HEAD> <? $monthName = array( /*定义$monthName[1]到$monthName[12]*/ 1=>"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", /*定义$monthName["Jan"]到$monthName["Dec"]*/ "Jan"=>"January", "Feb"=>"February", "Mar"=>"March", "Apr"=>"April", "May"=>"May", "Jun"=>"June", "Jul"=>"July", "Aug"=>"August", "Sep"=>"September", "Oct"=>"October", "Nov"=>"November", "Dec"=>"December", /*定义$monthName["Jan"]到$monthName["Dec"]*/ "January"=>"January", "February"=>"February", "March"=>"March", "April"=>"April", "May"=>"May", "June"=>"June", "July"=>"July", "August"=>"August", "September"=>"September", "October"=>"October", "November"=>"November", "December"=>"December" ); /*打印相关的元素*/ print("Month <B>5</B> is <B>" . $monthName[5]. "</B><BR>\n"); print("Month <B>Aug</B> is <B>" . $monthName["Aug"] . "</B><BR>\n"); print("Month <B>June</B> is <B>" . $monthName["June"] . "</B><BR>\n"); ?> </BODY> </HTML> 创建一个多维数组 <HTML> <HEAD> <TITLE>创建一个多维数组</TITLE> </HEAD> <? $Cities = array( //二维数组array() "华北地区"=>array( "北京市", "天津市", "石家庄" ), "西北地区"=>array( "西安", "拉萨" ) ); print("华北地区: ".$Cities["华北地区"][0]); //打印$Cities["华北地区"][0] ?> </BODY> </HTML> PHP 4.0实现表格状打印 <HTML> <HEAD> <TITLE>实现表格状打印</TITLE> </HEAD> <BODY> <? /* ** 数据表格化 */ print("<TABLE bgcolor='ffccoo' BORDER=\"1\">\n"); // 表格开始 for($Row=1; $Row <= 12; $Row ++) { print("<TR>\n"); // 开始行 // do each column for($Column=1; $Column <= 12; $Column ++) { print("<TD>");//开始列 print($Row * $Column);//表格元素乘积 print("</TD>"); } print("</TR>\n"); // 行结束 } print("</TABLE>\n"); // 表格结束 ?> </BODY> </HTML> 查看系统的一些变量 <HTML> <HEAD> <TITLE>查看PHP的环境变量</TITLE> </HEAD> <BODY> <? print("你正在用文件的名字为: "); print(__FILE__); print(" <BR>\n"); print("<hr>"); print("你的操作系统为: "); print(PHP_OS); print("<hr>"); print("你的php的版本为: "); print(PHP_VERSION) ?> </BODY> </HTML> 打开本地或者远程文件 <HTML> <HEAD> <TITLE>打开本地或者远程文件</TITLE> </HEAD> <BODY> <? print("<H3>通过http协议打开文件</H3>\n"); // 通过 http 协议打开文件 if(!($myFile = fopen("d:web/web/php/test/data.txt", "r"))) { print("文件不能打开"); exit; } while(!feof($myFile)) //循环 { // 按行读取文件中的内容 $myLine = fgetss($myFile, 255); print("$myLine <BR>\n"); } // 关闭文件的句柄 fclose($myFile); ?> </BODY> </HTML> 打开文件的几种方式比较 <HTML> <HEAD> <TITLE>读取文件内容</TITLE> </HEAD> <BODY> <? // 打开文件同时打印文件的每一个字符 if($myFile = fopen("data.txt", "r")) { while(!feof($myFile)) { $myCharacter = fgetc($myFile); print($myCharacter); } fclose($myFile); } ?> <? print("<hr>");?> <? // 打开文件同时打印文件的每一行 if($myFile = fopen("data.txt", "r")) { while(!feof($myFile)) { $myLine = fgets($myFile, 255); print($myLine); } fclose($myFile); } ?> <? print("<hr>");?> <? /* 打开文件同时打印文件的每一行, 同时去掉取回字符串中的 HTML 语言 */ if($myFile = fopen("data.txt", "r")) { while(!feof($myFile)) { $myLine = fgetss($myFile, 255); print($myLine); } fclose($myFile); } ?> </BODY> </HTML> 访问文件常见属性 <HTML> <HEAD> <TITLE>访问文件常见属性</TITLE> </HEAD> <BODY> <BR> <? print("文件的所有者(UID 值):"); print(fileowner("data.txt")."<br>"); print("文件的大小:"); print(filesize("data.txt")."<br>"); print("文件的类型:"); print(filetype("data.txt")."<br>"); ?> </BODY> </HTML> 调用文本文件内容 <HTML> <HEAD> <TITLE>调用文本文件内容</TITLE> </HEAD> <BODY> <CENTER> <? // 打开文件同时,打印每一行 $myFile = file( "data.txt"); for($index = 0; $index < count($myFile); $index++) { print($myFile[$index]."<BR>"); } ?> </CENTER> </BODY> </HTML> 创建目录函数 <HTML> <HEAD> <TITLE>创建目录函数</TITLE> </HEAD> <BODY> <? if(mkdir("myDir1", 0777)) //创建目录的函数 { print("目录创建成功"); //目录建立成功 } else { print("目录建立失败!"); //目录建立失败 } ?> </BODY> </HTML> 浏览目录 <HTML> <HEAD> <TITLE>浏览目录</TITLE> </HEAD> <BODY> <? // 使用表格浏览目录的结构 print("<TABLE BORDER=\"1\">\n"); // 创建表格的头 print("<TR><font color='red'>\n"); print("<TH>文件名</TH>\n"); print("<TH>文件的大小</TH>\n"); print("</font></TR>\n"); $myDirectory = opendir("."); // 建立操作目录的句柄 // 读出目录中的每一个子项 while($entryName = readdir($myDirectory)) { print("<TR>"); print("<TD>$entryName</TD>"); print("<TD ALIGN=\"right\">"); print(filesize($entryName)); print("</TD>"); print("</TR>\n"); } closedir($myDirectory); // 关闭目录 print("</TABLE>\n"); ?> </BODY> </HTML> PHP相关信息 <HTML> <HEAD> <TITLE>PHP相关信息</TITLE> </HEAD> <BODY> <? phpinfo(); ?> </BODY> </HTML> 常用的数值判断函数 <HTML> <HEAD> <TITLE>常用的数值判断函数</TITLE> </HEAD> <BODY> <? //判断数组 $colors = array("red", "blue", "green"); if(is_array($colors)) { print("colors is an array"."<br>"); } //双精度数判断 $Temperature = 15.23; if(is_double($Temperature)) { print("Temperature is a double"."<br>"); } //整数判断 $PageCount = 2234; if(is_integer($PageCount)) { print("$PageCount is an integer"."<br>"); } //对象判断 class widget { var $name; var $length; } $thing = new widget; if(is_object($thing)) { print("thing is an object"."<br>"); } //字符判断 $Greeting = "Hello"; if(is_string($Greeting)) { print("Greeting is a string"."<br>"); } ?> </BODY> </HTML> 文件上传界面 <HTML> <HEAD> <TITLE>文件上传界面</TITLE> </HEAD> <BODY><TABLE><CENTER> <? if($UploadAction){ $UploadAction=0; $TimeLimit=60; /*设置超时限制时间默认时间为 30s,设置为0时为不限时 */ set_time_limit($TimeLimit); If(($Upfile != "none")&& ($Upfile != "")) { $Filepath="d:\web\web\php\test"; //上载文件存放路径 $FileName=$Filepath.$Upfile_name; if($Upfile_size <1024) //上载文件大小 {$FileSize = (string)$Upfile_size . "字节";} elseif($Upfile_size <(1024 * 1024)) { $FileSize = number_format((double)($Upfile_size / 1024), 1) . " KB"; } else { $FileSize = number_format((double)($Upfile_size/(1024*1024)),1)."MB"; } if(!file_exists($FileName)) { if(copy($Upfile,$FileName)) {unlink($Upfile); echo "<br><br>\n"; echo "文件 $Upfile_name 已上载成功!"; echo "<br><br>\n"; echo "文件位置:$FileName"; echo "<br><br>\n"; echo "文件大小:$FileSize"; echo "<br><br>\n"; } else {echo "文件 $Upfile_name上载失败!"; } } else {echo "文件 $Upfile_name已经存在!"; } } else {echo "你没有选择任何文件上载!"; } set_time_limit(30); //恢复默认超时设置 } ?> <FORM ENCTYPE = "multipart/form-data" NAME = "SubmitForm" ACTION = "default.php" METHOD = "POST"> <INPUT TYPE = "hidden" NAME = "MAX_FILE_SIZE" VALUE ="1000000"> <INPUT TYPE = "hidden" NAME = "UploadAction" VALUE = "1"> <TR><TD><INPUT NAME = "Upfile" TYPE = "file" SIZE = "30"></TD> </TR><TR><TD><INPUT NAME = "submit" VALUE = "提交" TYPE = "submit"> <INPUT NAME = "reset" VALUE = "重置" TYPE = "reset"></TD> </TR></FORM></CENTER></TABLE> </BODY> </HTML>
󰈣󰈤
日版宠物情人插曲《Winding Road》歌词

日版宠物情人2017的插曲,很带节奏感,日语的,女生唱的。 最后听见是在第8集的时候女主手割伤了,然后男主用嘴帮她吸了一下,插曲就出来了。 歌手:Def...

兄弟共妻,我成了他们夜里的美食

老钟家的两个儿子很特别,就是跟其他的人不太一样,魔一般的执着。兄弟俩都到了要结婚的年龄了,不管自家老爹怎么磨破嘴皮子,兄弟俩说不娶就不娶,老父母为兄弟两操碎了心...

网络安全治理:国家安全保障的主要方向是打击犯罪,而不是处置和惩罚受害者

来源:中国青年报 新的攻击方法不断涌现,黑客几乎永远占据网络攻击的上风,我们不可能通过技术手段杜绝网络攻击。国家安全保障的主要方向是打击犯罪,而不是处置和惩罚...

 
 
 
>>返回首页<<
 为你推荐
 
 
 
 转载本文
 UBB代码 HTML代码
复制到剪贴板...
 
 
 热帖排行
 
单纯美女 迷人女孩
校园甜美少女
忍辱负重
大学校园
 
 
王朝网络微信公众号
微信扫码关注本站公众号wangchaonetcn
 
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
©2005- 王朝网络 版权所有