<?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));
?>
day1
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.