day1

来源:互联网 发布:notepad 排版json 编辑:程序博客网 时间:2024/05/04 10:04

<?php
/*
 * Created on 2010-1-26
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
//1 echo date("Y:m:d H:i:s",strtotime("-1 day"));
//2:print_r作用
//$location = array('Leon Atkinson'=>'home',
//        'john villarreal'=>'away',
//        'leon atkinson'=>'away',
//        'Carl porter'=>'home',
//        'Jeff McKillop'=>'away',
//        'Rick Marazzani'=>'away',
//        'bob dibetta'=>'away',
//        'Joe Tully'=>'home'
//        );
//
//    print_r(array_change_key_case($location, CASE_UPPER));
//3:翻转字符串
//        function reverse($var)
//        {
//            $res="";
//            for($i=0,$j=strlen($var);$i<$j;$i++)
//            {
//                $res=$var[$i].$res;
//            }
//            return $res;
//        }
//        $tmpvar="wofang";
//        $res=reverse($tmpvar);
//        echo $res;
//4:编码
//    print("test");
//5:引用
//        $empty = '';
//        $null = NULL;
//        $bool = FALSE;
//        $notSet;
//        $array = array();
//        //以下是问题
//        $a = "hello";
//        $b = &$a;
//        unset($b);
//        $b = "world";
//        //答案为:hello
//        echo $a;

//6:获得主机服务器地址
//        $ip=gethostbyname ("");
//        echo $ip;

//7:一些路径信息

    //本页地址,SCRIPT_NAME也可以:php/test.php
//    echo '$_SERVER[PHP_SELF] : ' . $_SERVER['PHP_SELF']."<br />";
//    //链接到当前页面的前一页面的 URL 地址:
//    echo '$_SERVER[HTTP_REFERER] :' . $_SERVER['HTTP_REFERER']."<br />";
//
//    //其它的见参考手册:语言参考》变量》预定义变量
//    //前执行脚本的绝对路径名:D:Inetpubwwwrootphp est.php
//    echo '$_SERVER["SCRIPT_FILENAME"] : ' . $_SERVER["SCRIPT_FILENAME"]."<br />";
//    //正在浏览当前页面用户的 IP 地址:127.0.0.1
//    //获得客户端ip地址
//    echo '$_SERVER["REMOTE_ADDR"] : ' . $_SERVER["REMOTE_ADDR"]."<br />";
//    //查询(query)的字符串(URL 中第一个问号 ? 之后的内容):id=1&bi=2
//    echo '$_SERVER["QUERY_STRING"] : ' . $_SERVER["QUERY_STRING"]."<br />";
//    //当前运行脚本所在的文档根目录:d:inetpubwwwroot
//    echo ' $_SERVER["DOCUMENT_ROOT"] :' . $_SERVER["DOCUMENT_ROOT"]."<br />";

//8:取余
//        echo 8%(-2)."<br />";//0
//        //取模 $a % $b 在 $a 为负值时的结果也是负值。输出-2
//        echo ((-8)%3)."<br />";
//        //输出2
//        echo (8%(-3))."<br />";
// swap newlines for break tags

//9:正则
//    $text = "line1/nline2/nline3/n";
//    print(preg_replace("|/n|", "<br>", $text));
//
//    print("<hr>/n");
//
//    //mix up these words
//    $text = "one two three four";
//    print(preg_replace("|([a-z]+) ([a-z]+) ([a-z]+) ([a-z]+)|",
//        "//4 //2 //1 //3", $text));

//    function rotateColor($match)
//    {
//        static $color = 0;
//        static $colorList = array(0=>'red','blue','green');
//        $text = "<span style=/"color:{$colorList[$color]}/">" .
//            implode($match) .
//            "</span>";
//
//        $color++;
//
//        return($text);
//    }
//
//    //color each match with rotating colors
//    $text = "line1/nline2/nline3/n";
//    print(preg_replace_callback("|line[0-9]|", 'rotateColor',
//        $text));

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

//10:遍历文件

//function my_scandir($dir)
//{
//    $files=array();
//    if(is_dir($dir))
//     {
//        if($handle=opendir($dir))
//         {
//            while(($file=readdir($handle))!==false)
//             {
//                if($file!="." && $file!="..")
//                 {
//                    if(is_dir($dir."/".$file))
//                     {
//                        $files[$file]=my_scandir($dir."/".$file);
//                     }
//                    else
//                     {
//                        $files[]=$dir."/".$file;
//                     }
//                 }
//             }
//            closedir($handle);
//            return $files;
//         }
//     }
//}
//print_r(my_scandir("D:/gaogesoft/NotepadCodeLab/NotepadCodeLab/Notepadv1/src/com/android/demo"));

//11:print_r 递归打印数组

// $location = array('Leon Atkinson'=>'home',
//        'john villarreal'=>'away',
//        'leon atkinson'=>'away',
//        'Carl porter'=>'home',
//        'Jeff McKillop'=>'away',
//        'Rick Marazzani'=>'away',
//        'bob dibetta'=>'away',
//        'Joe Tully'=>'home',
//        'innerArray' => array(1,2,3)
//        );
//
//    print_r($location);


// print the current directory in unordered list
//    print("<ul>/n");
//
//    // open directory
//    $myDirectory = opendir(".");
//
//    // get each entry
//    while(FALSE !== ($entryName = readdir($myDirectory)))
//    {
//           print("<li>$entryName</li>/n");
//    }
//
//    // close directory
//    closedir($myDirectory);
//
//    print("</ul>/n");


//12:strpos函数
//$text = "Hello, World!";
//
//    //check for a space
//    if(strpos($text, 32))
//    {
//        print("There is a space in '$text'/n");
//    }
//
//    //find where in the string World appears
//    print("World is at position " . strpos($text, "World") . "/n");


$text = "Wow!  This is neat.";
    $original = "!.";
    $translated = ".?";

    // turn sincerity into sarcasm
    print(strtr($text, $original, $translated));




?>






原创粉丝点击