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

PHP实用小程序(四)

时间:2015-08-25 23:33:35      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:

<HTML>
<HEAD>
<TITLE>访问文件时间属性</TITLE>
</HEAD>
<BODY>
<?
    $LastAccess = fileatime("data.txt");
    print("文件最后的存取时间为:");
    print(date("l F d, Y", $LastAccess));
    print("<br>");
?>
<?
    $LastA = filectime("data.txt");
    print("文件最后的改变时间:");
    print(date("l F d, Y", $LastA));
    print("<br>");
?>
<?
    $LastB = filemtime("data.txt");
    print("文件最后的修改时间:");
    print(date("l F d, Y", $LastB));
    print("<br>");
?>
</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>
<HTML>
<HEAD>
<TITLE>取得浏览器的信息</TITLE>
</HEAD>
<BODY>
<?php
function list_array ($array)        //定义函数
    {
         while (list ($key, $value) = each ($array)) 
         {
         $str= "<b>$key:</b> $value<br>\n";
         }
        return $str;
    }
 echo "$HTTP_USER_AGENT<hr>\n";
 $browser = get_browser();
 print("<br>");
 echo list_array ((array) $browser);
?>
</BODY>
</HTML>
<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>
<?
    // 构造一个数组变量
    $users = array("bob"=>"Yobert",  
        "steve"=>"Btephen", 
        "jon"=>"Aonathon");
    
    for(reset($users); $index=key($users); next($users))
    {
        print("$index : $users[$index] <BR>\n");
    }   
    print("<hr>");
    // 使数组排序
    asort($users);

    // 打印排序后的数组
    for(reset($users); $index=key($users); next($users))
    {
        print("$index : $users[$index] <BR>\n");
    }
?>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE>常用数组函数</TITLE>
</HEAD>
<BODY>
<?
    $colors = array("red", "green", "blue","yellow");
    print("数组的个数:".count($colors)."<br>");//数组的个数
    print("数组的当前值:".current($colors)."<br>");//当前的值
    end($colors);
    print("数组的最后一个的值:".current($colors)."<br>");
    print("<hr>");
    $slice = each($colors);//
    print("each()函数的使用:"."<br>");
    print($slice[0] . "====" . $slice[1] . "<BR>\n");
    print($slice[‘key‘] . "====" . $slice[‘value‘] . "<BR>\n");
?>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE>常用字符串函数(一)</TITLE>
</HEAD>
<BODY>
<?
    $first = "abc";
    $second = "aBc";
    if(strcmp($first, $second) == 0)//字串比较
    {
        print("字符串相等:"."<hr>");
    }
    else
    {
        print("字符串不相等"."<hr>");
    }
?>
<?
    print("a short string ".strlen("a short string")."<hr>");//字串长度
?>
<?
    $text = "hello world";
    print(strpos($text, "w")."<hr>");//寻找字串中某字元最先出现处
?>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE>常用字符串函数(二)</TITLE>
</HEAD>
<BODY>
<?
    $text = "My dog‘s name is Angus.";
    //print Angus
    print(substr($text, 17, 5)."<hr>");//取出子串
?>
<?
    //切开字串
    // create a demo string
    $line = "leon\tatkinson\tleon@clearink.com";

    // loop while there are still tokens
    for($token = strtok($line, "\t");
        $token != "";
        $token = strtok("\t"))
    {
        print("token: $token<BR>\n");
    }
?>
<?
    //传回字串中某字串开始处至结束的字串
    $text = "Although this is string, it‘s not very long.";
    print("<hr>".strstr($text, ",")); 
?>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE>常用字符串函数(三)</TITLE>
</HEAD>
<BODY>
<?
    //颠倒字串
    print("abcdefg  颠倒  ");
    print(strrev("abcdefg")."<hr>");

    //小写字串
    print("小写: ".strtolower("Hello World")."<hr>");

    //大写字串
    print("大写: ".strtoupper("Hello World")."<hr>");

    //去空格
    $text = "     whitespace      ";
    print("\"" . trim($text) . "\"");
?>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE>编码和解码函数</TITLE>
</HEAD>
<BODY>
<?
    $data = "VGhpcyBpcyBhIAptdWx0aS1saW5lIG1lc3NhZ2UK";//解码前的值
    print ($data);
    print(base64_decode($data));               //进行解码
?>
<?
    print("<hr>");
    $text = "这是一个多行信息\n";
    print ($text);
    print(base64_encode($text));               //编码
?>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE>常用数学函数(一)</TITLE>
</HEAD>
<BODY>
<?
    print(abs(-13));//打印绝对值
?>
<?
    // 从 -1 到1打印acos函数的值
    print("<TABLE BORDER=\"1\">\n");
    print("<TR><TH>x</TH><TH>acos(x)</TH></TR>\n");
    for($index = -1; $index <= 1; $index += 0.25)
    {
        print("<TR>\n");
        print("<TD>$index</TD>\n");
        print("<TD>" . acos($index) . "</TD>\n");
        print("</TR>\n");
    }
    print("</TABLE>\n");
?>
<?
    //  从 -1 到 1打印asin函数的值
    print("<TABLE BORDER=\"1\">\n");
    print("<TR><TH>x</TH><TH>asin(x)</TH></TR>\n");
    for($index = -1; $index <= 1; $index += 0.25)
    {
        print("<TR>\n");
        print("<TD>$index</TD>\n");
        print("<TD>" . asin($index) . "</TD>\n");
        print("</TR>\n");
    }
    print("</TABLE>\n");
?>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE>常用时间函数(二)</TITLE>
</HEAD>
<BODY>
<?
    print("pi=".pi());
    print("<br>");
    print("sin(0.5 * pi())=".sin(0.5 * pi()));
    print("<br>");
    print("cos(2 * pi())=".cos(2 * pi()));
    print("<br>");
    
    //打印从1到100中间的10个随机的数
    for($index = 0; $index < 10; $index++)
    {
        print(rand(1,100) . "<BR>\n");
    }
?>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE>日期检查函数</TITLE>
</HEAD>
<BODY>
<?
    if(checkdate(2,18,1970))//检查日期函数
    {
        print("2,18,1970  :"."这是一个正确的日期格式");
    }
    else
    {
        print("这不是一个正确的日期格式");
    }
    if(checkdate(52,18,1970))//检查日期函数
    {
        print("这是一个正确的日期格式");
    }
    else
    {
        print("52,18,1970  :"."这不是一个正确的日期格式");
    }
?>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE>常用时间函数(一)</TITLE>
</HEAD>
<BODY>
<?
    print(date("h:i A l"));
    print("<BR>\n");
    print(date("F dS, Y"));
?>
<?
    $current_date = getdate(time());
    print("<hr>");
    printf("%d:%d:%d", 
        $current_date["hours"],
        $current_date["minutes"],
        $current_date["seconds"]);
?>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE>常用时间函数(二)</TITLE>
</HEAD>
<BODY>
<?
    print("开始时间:". microtime() . "<BR>\n");

    for($index = 0; $index < 10; $index++)
    {
        print("tick ");
    }
    print("<br>"."停止: " . microtime() . "<BR>\n");
?>
<?
    $CurrentHour = date("h");

    print("从现在开始50小时以后为: ");
    print(date("h:i A l F dS, Y",
        mktime($CurrentHour+50)));
    print("<BR>\n");
?>
<?
    $CurrentTime = time();

    print($CurrentTime);
?>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE>程序暂停函数</TITLE>
</HEAD>
<BODY>
<?
    print(microtime());
    sleep(10);      //程序暂停10s
    print("<br>\n");
    print(microtime());
    print("<hr>");
    print(microtime());
    usleep(30);     //暂定30ms
    print("<br>\n");
    print(microtime());
?>
</BODY>
</HTML>

 

PHP实用小程序(四)

标签:

原文地址:http://www.cnblogs.com/yxhblogs/p/4758756.html

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