|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
如果不会怎么办,我的视频教程里有个最简单的留言板 最开始离不开模仿,老手 经典轮回例子
<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>兴趣可能会慢慢消亡,所以适当培养兴趣会激发自己无线的乐趣,有了乐趣,编程有啥难的。 |
|