PHP4-chap3

字元與運算子

程式碼

//'3.1'跳脫字元
$session_name = $session_txt['3.1'];
echo $session_name."<br>";
//$text = "This text goes\nacross several\nlines\t\"and this quotion is indented\"";
echo nl2br("This text goes\nacross several\nlines\t\"and this quotion is indented\"");

$message="
<fieldset><legend><font color=red>TIPS</font></legend>
   我們會用到\符號來跳脫後面的符號,至於N->斷行、T->定位<br>
   都沒有用,要能有用,必須加上<font color=red>nl2br()</font>函式來轉換。
<br>
</fieldset>
";

echo $message."<br>";
//'3.2'運算子
$session_name = $session_txt['3.2'];
echo $session_name."<br>";

@define(CREATE_RECORDS, 1);
@define(DELATE_RECORDS, 2);
@define(ALTER_RECORDS, 4);
@define(ADMINISTATOR, 8);

$user_permissions = CREATE_RECORDS |ALTER_RECORDS;

echo (($user_permissions & CREATE_RECORDS) ? "user can creats records<br>" : "");

@define (TWO, 2);
@define (FOUR, 4);

echo (TWO << FOUR)."<br>";
echo (FOUR >> TWO)."<br>";

//$Myconn=$conn;  //使用mysqli_connect連線

$message="
<fieldset><legend><font color=red>TIPS</font></legend>
   位元運算子:且(&)、或(|)、互斥(^)、補數(~)、左移(<<)、右移(>>)<br>
  左移(Shift Left):<br>
     echo 11<<2;<br> 
     11往左邊移動2個位元,output:44<br>
     左移運算就是將全部位元往左移兩格,然後右邊補上0<br>
     11(1011) ->左移一次,右邊補0-> 22(10110) ->左移一次,右邊補0-> 44(101100)<br>
   <br>
   數值運算子:相加(+)、相乘(*)、相減(-)、相除(/)、餘數運算子(%)。<br>
    <br>
   比較運算子:小於(<)、小於等於(<=)、大於(>)、大於等於(>=)。傳回true或false<br>
     <br>
   邏輯運算子:且(and或&&)、或(or或||)、非(!)、互斥(xor)。傳回true或false<br><br>
</fieldset>
";

echo $message."<br>";

php array()函式

array()函式是接收一串以逗號為區隔的資料,放入陣列中。

$aLanguages = array("Arabic", 3 => "German", "Korean", "Tagalog");
echo $aLanguages[0] ;   // "Arabic"
echo $aLanguages[3] ;   // "German"
echo $aLanguages[4] ;   // "Korean"
echo $aLanguages[5] ;   // "Tagalog"

若我們沒有指定任何索引值,這些陣列的元素會被指派預設的索引值。要明確指定array()構件中的索引值的話,要用 =>運算子。

PHP-Cookbook-chapte13

程式碼

//'13.1'擷取其他程式的輸出
$session_name = $session_txt['13.1'];
echo $session_name."<br>";
//echo ROOT_PATH."<br>";


$current_date = 'date';

$pp =popen('date','r');
while ($line = fgets($pp,1024)){
	$output .=$line;
}
pclose($pp);

show_array($output);
exec('date',$output_1);
print implode ("\n",$output_1)."<br>";  
show_array($output_1);

$message="
<fieldset><legend><font color=red>TIPS</font></legend>
   exec()函數。此函式會開啟一個管線連接到某個程式,並將該程式所有的輸出<br>
   逐行放到陣列中(欲填入的陣列當成第二個參數)。
   	
<br>
</fieldset>
";
echo $message."<br>";
//'13.2'印出程式的輸出
$session_name = $session_txt['13.2'];
echo $session_name."<br>";
//echo ROOT_PATH."<br>";

passthru('date');


$message="
<fieldset><legend><font color=red>TIPS</font></legend>
  passthru()函式 
<br>
</fieldset>
";
echo $message."<br>";

PHP-Cookbook-chapte9

程式碼

//'9.1'建立物件
$session_name = $session_txt['9.1'];
echo $session_name."<br>";
//echo ROOT_PATH."<br>";

class Name{
	var $property1;
	var $property2;
	
	function print_name($first_name,$last_name){
		print "You first name is :$first_name,<br>";
		print "and your last name :$last_name.";
	}
}

$obj = &new Name;
$obj->firstname='Oliver';
$obj->lastname='Butin';

$obj->print_name($obj->firstname,$obj->lastname); 


$message="
<fieldset><legend><font color=red>TIPS</font></legend>
    \$obj = &new Name;<br>
    \$obj->firstname='Oliver';<br>
    \$obj->lastname='Butin';<br><br>

     \$obj->print_name(\$obj->firstname,\$obj->lastname); 
<br>
</fieldset>
";
echo $message."<br>";
//'9.2'在類別裡存取變數
$session_name = $session_txt['9.2'];
echo $session_name."<br>";
//echo ROOT_PATH."<br>";

class Name1 {
	var $firstname;
	var $lastname;
	
	function print_name(){
		print 'Firstname :'. $this->firstname;
		print '<br>Lastname :'. $this->lastname."<br>";
	}

    function change_name ($name){
		$name = preg_split('/\s+/',$name);
		$this->firstname = $name[0];
		$this->lastname = $name[1];
	}

}

$obj = &new Name1;
$obj->change_name("Sterlling Hughes");
$obj->print_name();
$obj->change_name("Andrei Zmievski");
$obj->print_name();

$message="
<fieldset><legend><font color=red>TIPS</font></legend>
    取class的變數 \$this->firstname,不用加\$符號。
<br>
</fieldset>
";
echo $message."<br>";
//'9.4'設定公開和私有變數或函式
$session_name = $session_txt['9.4'];
echo $session_name."<br>";
//echo ROOT_PATH."<br>";

class Car {
	var $_name; // 私有變數
	var $brandname;
	
	function analyze(){
		if ($this->_name == "Corola"){
			$this->brandname = 'Toyota';
		}else {
			$this-_delete();
		}
	}
	function _delete(){
		$this->name ='';
		$this->brandname ='';
	}
}
	

$message="
<fieldset><legend><font color=red>TIPS</font></legend>
   如果要宣告函式和變數為類別所私有,你必須將它們放在函數內。<br>
   然而有個標準命名慣例,私有方法和變數應該有底線(_)開頭。
<br>
</fieldset>
";
echo $message."<br>";
//'9.5'撰寫建構函式(constructor)
$session_name = $session_txt['9.5'];
echo $session_name."<br>";
//echo ROOT_PATH."<br>";

class Human {
	var $name;
	
	function Human ($na){
		print "Wake up $na, you have been initalized!<br>";
		$this->name = $na;
	}
}
$obj = &new Human ('Stephen Hughes');


class SuperHuman extends Human {
	var $power;
	
	function SuperHuman($power){
		Human::Human(); //呼叫class Human 及 class 裡的 Human方法
		$this->$power = $power;
		print "You power is $power";
	}
	
	function user_power(){
	}
}
$obj1 = &new SuperHuman (10);
	

$message="
<fieldset><legend><font color=red>TIPS</font></legend>
  在PHP,建構函式是一個與類別名稱大小寫相同的函式,它可以接受參數<br>
  ,以便在初始化的時候讓物件有機會修改預設的資料。另外請注意,如果<br>
  親代類別也有一個建構函式,那麼當子類別產生物件時並不會呼叫親代的<br>
  建構函式。所以你必須手動作點工。<br>
  function SuperHuman(\$power){<br>
	<font color=red>
	Human::Human(); //呼叫class Human 及 class 裡的 Human方法
	</font>
	<br>
		\$this->\$power = \$power;<br>
		print 'You power is \$power';<br>
	}
	
<br>
</fieldset>
";
echo $message."<br>";
//'9.8'直接使用類別函式而不需產生物件
$session_name = $session_txt['9.8'];
echo $session_name."<br>";
//echo ROOT_PATH."<br>";

class Conversion {
	
	function feet_to_meters($feet){
		return $feet * 0.3054;
	}
}
$orgin_height = 6;
$average_height = Conversion::feet_to_meters($orgin_height);
print "輸入的$orgin_height 呎<br>";
print "換算成$average_height 公尺";

$message="
<fieldset><legend><font color=red>TIPS</font></legend>
    範例:原始碼<br>
	class Coversion {<br>
	function feet_to_meters(\$feet){<br>
		return \$feet * 0.3054;<br>
	   }<br>
}<br>
\$averge = Conversion::feet_to_meters(6);<br>
直接用符號::來用Conversion -class裡的方法feet_to_meters()<br>
也可以存取變數。
 
<br>
</fieldset>
";
echo $message."<br>";
//'9.9'直接存取親代類別的函式
$session_name = $session_txt['9.9'];
echo $session_name."<br>";
//echo ROOT_PATH."<br>";

class Computer {
	var $is_on = 1;
	
	function turn_on(){
		$this->is_on = 1;
		print "You turned me on";
	}
	
	function turn_off(){
		$this->is_on = 0;
		print "You turned me off";
	}
}

class HP extends Computer {
	var $processor = 0;
	var $hard_driver =0;
	
	function turn_on(){
		parent::turn_on();
		$this->processor = 1;
		$this->hard_drive = 1;
	}
	
	function turn_off(){
		$this->hard_drive = 0;
		$this->processor = 1;
		parent::turn_off();
	}
}

$message="
<fieldset><legend><font color=red>TIPS</font></legend>
    parent類別是個特殊類別,只能用::表示法存取。它可以讓你存取<br>
	親代類別的函式。
	
<br>
</fieldset>
";
echo $message."<br>";

PHP-Cookbook-chapte8

程式碼

//'8.5'在函式呼叫間維持變數值
$session_name = $session_txt['8.5'];
echo $session_name."<br>";
//echo ROOT_PATH."<br>";

function sequence_get_next_value()
{
		static $x =0;
		return $x++;
}

print sequence_get_next_value ()."=1st value <br>"; 
print sequence_get_next_value ()."=2nd value <br>";
print sequence_get_next_value ()."=3rd value <br>";


$message="
<fieldset><legend><font color=red>TIPS</font></legend>
     staric 變數 = 值,設定變數的維持值<br>
	 staic敘述是避免在函式中使用全域變數的良好方法。在PHP程式<br>
	 執行中,它會在函式間記得\$x的值,這表示程式執行完之後,PHP<br>
	 會忘記此靜態變數的值。
<br>
</fieldset>
";
echo $message."<br>";
//'8.8'動態建立匿名函式
$session_name = $session_txt['8.8'];
echo $session_name."<br>";
//echo ROOT_PATH."<br>";

function greet ($type){
	return create_function ('$greeting',
							"print \"$type:\$greeting <br> \";");
}
$greeting1 =greet("Casual");
$greeting2 =greet("Formal");

$greeting1("How's it going?");
$greeting1("What's up doc?");

$greeting2("Hello");
$greeting2("Hello,my name is Sterling, it is a pleasure to meet you."); 




$message="
<fieldset><legend><font color=red>TIPS</font></legend>
     create_function()函式,會動態建立一個函式,並以第一個參數當作<br>
	 該函式的參數,以第二個參數當作該函式的程式碼。它會傳回該函式名稱,<br>
	 然後你就可以呼叫該函式。這種粗糙的包裝形式有許多用途,包括call_back()<br>
	 函式。
<br>
</fieldset>
";
echo $message."<br>";
//'8.10'取得任意數量的參數
$session_name = $session_txt['8.10'];
echo $session_name."<br>";
//echo ROOT_PATH."<br>";

$input_record_separator = " ";

function perl_print (){
	$args =func_num_args();
	/*
	for ($idx = 0; $idx <$argc; $idx++){
		$current_arg = func_num_args($idx);
		print $current_arg.$input_record_separator;
	}
	*/
	foreach ($args as $arg){
		print $arg. $input_record_separator;
	}
}
function perl_print1 (){
	
	$argc =func_num_args();
	for ($idx = 0; $idx <$argc; $idx++){
		$current_arg = func_num_args($idx);
		print $current_arg.$input_record_separator;
	}
	
}

perl_print("Hello World \n","My Name is ","Sterling");
perl_print1("Hello World \n","My Name is ","Sterling","234");

$message="
<fieldset><legend><font color=red>TIPS</font></legend>
   PHP提供一組方便的函式,可接受任意數量的參數。func_num_args()   
<br>
</fieldset>
";
echo $message."<br>";

PHP傳址呼叫、傳值呼叫、傳遞參考

常常看到函數前會加一個&符號,&到底是什麼意思?

例如

funcion &get_product_list ($department){
    $product_list = array();
    return $product_list;
}

$products = &get_product_list('rd')

這裡的加上&符號是什麼意思呢?查一下知道是用傳遞參考的方法呼叫函數。函數傳遞資料有三種方式:傳址呼叫(pass by adress)、傳值呼叫(pass by value)、傳遞參考(pass by reference)區別在哪裡呢?以下說明

& ->取址運算子

*->取值運算子

函數中資料的傳遞:傳值、傳址、傳參考
以下的說明是每種程式語言都通用的觀念,但不同程式語言有不同的語法,以及不同的程式語言不一定都支援全部的傳遞方式,要看你使用的是哪種程式語言。

PHP-Cookbook-chapter7

程式

//'7.1'處理時間標記
$session_name = $session_txt['7.1'];
echo $session_name."<br>";
//echo ROOT_PATH."<br>";

$fn = $file_name = ROOT_PATH."/test/6-10.txt";

print "$fn was last accessed on:". fileatime ($fn)."<br>";
print "$fn was last change on:". filectime ($fn)."<br>";
print "$fn was last modified on:". filemtime ($fn)."<br>";

if (touch ($fn,$date)){
	print "Timestamp changed....";
}else{
	print "Modification Failed";
}

$message="
<fieldset><legend><font color=red>TIPS</font></legend>
   在PHP中,copy()是更改檔案時間標記的唯一方式,而它唯一變更<br>
   的是檔案修改時間。因此,除非你用exec(),system()跳出PHP之外<br>
   ,否則你只能更改檔案的mtime。
   
<br>
</fieldset>
";
echo $message."<br>";
//'7.2'移除檔案
$session_name = $session_txt['7.2'];
echo $session_name."<br>";
//echo ROOT_PATH."<br>";


$message="
<fieldset><legend><font color=red>TIPS</font></legend>
   用unlink()函式處理你要刪除的檔案。若成功傳回1,否則傳回0。<br>
   因此你可以用or運算子或if-else區塊。<br>
   如果你想刪除數個檔案,你可以用forch迴圈讀取陣列元素,然後<br>
   刪除每個檔案。<br>
   foreach (\$file as \$file){ <br>
        unlink(\$file); <br>
		or die ('Waring str');<br>
   }
<br>
</fieldset>
";
echo $message."<br>";
//'7.3'拷貝或移動檔案
$session_name = $session_txt['7.3'];
echo $session_name."<br>";
//echo ROOT_PATH."<br>";


$message="
<fieldset><legend><font color=red>TIPS</font></legend>
   在PHP中,copy()函式<br>
   if (copy(\$orginal,\$new)){<br>
      print '成功'; <br>
   }else{  <br>
		print '失敗'; <br>
   }  <br>
   或者如果你需要移動檔案,就用rename()函式 <br>
   rename(\$original,\$new) <br>
      or die ('warmingstr')
<br>
</fieldset>
";
echo $message."<br>";
//'7.5'分析檔名的各個組成部分
$session_name = $session_txt['7.5'];
echo $session_name."<br>";
//echo ROOT_PATH."<br>";

$fn = ROOT_PATH."/test/6-11.php";

$pinfo = pathinfo ($fn);
print "Directory name is :".$pinfo [dirname ] ."\n<br>";
print "Filename is :".$pinfo [basename ]." \n<br>";
print "Ending is :".$pinfo [extension ]." \n<br>";




$message="
<fieldset><legend><font color=red>TIPS</font></legend>
     參數 dirname 檔案位在的目錄<br>
     參數 basename 檔案名稱<br>
     參數 extension 檔案副檔名,若它有的話
<br>
</fieldset>
";
echo $message."<br>";
//'7.8'循序處裡目錄中的檔案
$session_name = $session_txt['7.8'];
echo $session_name."<br>";
//echo ROOT_PATH."<br>";

$dir_name = ROOT_PATH."/test";
$dh = dir ($dir_name);
echo "方法一<br>";
while ($entry = $dh ->read()){
	print $entry ."\n";
}
$dh->close();

$dh = opendir ($dir_name);
echo "<br>方法二<br>";
while ($entry = readdir ($dh)){
	print $entry ."\n";
}
closedir();

$message="
<fieldset><legend><font color=red>TIPS</font></legend>
    你可以用dir()函式透過一虛擬的物件處裡目錄或用opendir()<br>
	、readdir()、和closedir()來讀取目錄。
 	 
<br>
</fieldset>
";
echo $message."<br>";

PHP-Cookbook-chapter6

程式

//'6.3'建立暫存檔
$session_name = $session_txt['6.3'];
echo $session_name."<br>";
//echo ROOT_PATH."<br>";

$tmp = tempnam (ROOT_PATH."/test","tmpFile");

$fp = @fopen ($tmp,"w");
if (!@fp){
	die ("無法開啟 $tmp");
}

fputs ($fp,"Hello World <br>");
fputs ($fp,"Another Line in a Temporary File");

@fclose ($fp);

$fp =@fopen ($tmp, "r");
if(!$fp){
	die ("無法開啟 $tmp");
}

while ($line = @fgets ($fp,1024)){
	print $line;
}
@fclose ($fp);
@unlink ($tmp)
or die ("無法刪除 $tmp");

	
$message="
<fieldset><legend><font color=red>TIPS</font></legend>
   tempnam(位置,前綴詞)函式會在指定的目錄下產生一個指定<br>
   前綴詞唯一檔。檔案建立後,會傳回檔名(本例指定給\$tmp_file_name)<br>
   ,程式節結束後,記得用unlink()刪除檔案。
   
<br>
</fieldset>
";
echo $message."<br>";
//'6.4'將檔案存到程式裡
$session_name = $session_txt['6.4'];
echo $session_name."<br>";
//echo ROOT_PATH."<br>";

$file_name = ROOT_PATH."/test/3-1.txt";
$fp = @fopen ($file_name,"rb") or
	die ("無法開啟{$file_name}");

clearstatcache(); //清除快取

$f_contents = fread ($fp,filesize ($fp)); //方法一
//echo $f_contents; 

unset ($f_contents);
$f_contents = show_array(file ($file_name));//方法二

unset ($f_contents);
$f_contents = implode ("",file ($file_name));//方法三
echo $f_contents."<br>";

unset ($f_contents);
while ($line = @fgets ($fp,1024)){  //方法四
	$f_contents .=$line; 
}
echo $f_contents;

@fclose ($fp);

$message="
<fieldset><legend><font color=red>TIPS</font></legend>
    fread()讀取資料,並搭配filesize(),將檔案載入變數中<br>
	如果想把檔案一行一行存入陣列,就用file()函式。<br>
	另外要使用filesize()時,最好用clearstrstcache()清除快取。
<br>
</fieldset>
";
echo $message."<br>";
//'6.8'鎖定檔案
$session_name = $session_txt['6.8'];
echo $session_name."<br>";
//echo ROOT_PATH."<br>";

/*
Lockfile.inc
<?
function lock ($fp,$lock_level=LOCK_EX){
	@flock ($fp,$lock_level)
	or die ("無法以 $lock_level 鎖定檔案指標");
}
function unlock ($fp){
	@flock ($fp,LOCK_UN)
	or die ("無法解除鎖定");
}
?>
*/
include ("Lockfile.inc");

unset ($file_name);
$file_name = ROOT_PATH."/test/3-1.txt";

$fp = @fopen ($file_name,"wb")
		or die ("無法開啟 $file_name 以供寫入");

//寫入檔案前請務必取得獨佔鎖定(exclusive)
//這相當於 flock($fp,LOCK_EX)
lock ($fp);

fwrite ($fp,"Hello");

//解除檔案鎖定,這相當於 flock($fp,LOCK_UN)
unlock ($fp);
@fclose ($fp);



$message="
<fieldset><legend><font color=red>TIPS</font></legend>
    你想確保存檔案期間不會有其他程式存取,使用flock()函式<br>
	參數為 LOCK_EX 鎖定、LOCK_UN 解除鎖定
<br>
</fieldset>
";
echo $message."<br>";
//'6.10'顯示文字檔內容
$session_name = $session_txt['6.10'];
echo $session_name."<br>";
//echo ROOT_PATH."<br>";

$read_file = ROOT_PATH."/test/6-10.txt";
$fp = @fopen ($read_file,"rb")
		or die (" Cannot read the $read_file !");
$twenty_byes = fread ($fp,20);
fpassthru($fp);

echo "<br>";

readfile ($read_file);

echo "<br>";

print implode ("<br>",file ($read_file));



@fclose ($fp);

$message="
<fieldset><legend><font color=red>TIPS</font></legend>
  有三個函式可以讀取文字檔內容。fpassthru()、readfile()、<br>
  implode(\"區隔符號\",file(檔案位置))
<br>
</fieldset>
";
echo $message."<br>";
//'6.22'隨機排列檔案內容
$session_name = $session_txt['6.22'];
echo $session_name."<br>";
//echo ROOT_PATH."<br>";

$fn = ROOT_PATH."/test/6-10.txt";
$reg_array = file($fn);

srand ((double)microtime()*1000000);
shuffle ($reg_array);

$fp = @fopen($fn,"wb") or die ("無法開啟檔案 $fn");
	fputs ($fp,implode ("",$reg_array));

echo "<br>以下是亂數排列後的內容:<br>";	
readfile ($fn);
echo "<br>";


$fn1 = ROOT_PATH."/test/6-11.txt";
srand ((double)microtime()*1000000);
$fp1 = @fopen($fn1,"rb") or die ("無法開啟檔案 $fn");
foreach (file ($fn1) as $line){
	$words = preg_split ("/\s+/",$line);
	shuffle ($words);
	$data .= implode ("",$words."\n");
}

print "herd".$data; //有問題出不來

@fclose ($fp1) or die ("無法關閉檔案 $fn");
@fclose ($fp) or die ("無法關閉檔案 $fn");

$message="
<fieldset><legend><font color=red>TIPS</font></legend>
  首先用file()函式將檔案載入陣列,現在陣列中已經有檔案的每一行<br>
  內容,我們就可以將陣列個元素隨機排列。接著我們可以為shuffle()<br>
  設定亂數產生器的起點,然後將陣列傳給shuffle()(請注意不需要<br>
  shuffle()的傳回值,因為它直接操控陣列本身。
<br>
</fieldset>
";
echo $message."<br>";

PHP-Cookbook-chapter5

程式

//'5.1'指定樣式替換的結果
$session_name = $session_txt['5.1'];
echo $session_name."<br>";


	
$message="
<fieldset><legend><font color=red>TIPS</font></legend>
   PHP的常規表示式並不影響到他們所處理的字串內容,而是根據所給的<br>
   樣式和字串傳回一新的字串,因此需要一個新的變數來接它。
   
<br>
</fieldset>
";
echo $message."<br>";
//'5.9'檢驗網頁傳送的資料
$session_name = $session_txt['5.9'];
echo $session_name."<br>";

@exec (escapeshellcmd ($input),$output);

if (!@empty ($name)){
	die ("You have to supply Your name");
}
	
$message="
<fieldset><legend><font color=red>TIPS</font></legend>
   exec (esecapeshellcmd (\$input),\$output)會跳脫所有的<br>
   shell萬用字元,讓使用者輸入的內容無法危害你的系統安全。<br>
   empty()函式只檢查有沒有值,不會檢查是否為有效值。
   
<br>
</fieldset>
";
echo $message."<br>";
//'5.12'檢查重複的字
$session_name = $session_txt['5.12'];
echo $session_name."<br>";

$seen = array();
$paragraph ="The ugly lady chased the handsome man";
$paragraph =preg_split("/\s+/",$paragraph);

foreach ($paragraph as $word){
	@$seen [strtolower ($word)]++;
}
$seen = show_array($seen);
print "There were $seen [the] occurrences of the word 'the' <br>";

function get_dupes ($str){
	$str = strtolower ($str);
	$words = preg_split ("/\s+/",$str);
	$seen = array();
	$start_pos = array();
	$i = 0;
	
	foreach ($words as $word){ //取字串的迴圈
	    //二維的陣列,包含單字的位置
		@$seen [$word][$i] = strpos ($str,$word,$start_pos [$word]);
		//指定起始位置以避免重複
		$start_pos [$word] = $seen [$word][$i] +strlen ($word);
		$i++;
	}
	return ($seen);
}
$str = " The The the Hello Truck Hello The the Jester Rye";
echo $str."<br>";
$duplicates = get_dupes ($str);
var_dump ($duplicates); //印出陣列的相關訊息

	
$message="
<fieldset><legend><font color=red>TIPS</font></legend>
    var_dump()印出陣列的相關訊息<br>
	strtolower()將字串轉成小寫<br>
    strpos()找出字串首次出現的位置<br>
	strlen()字串的長度
<br>
</fieldset>
";
echo $message."<br>";
//'5.13'減少輸入的需要
$session_name = $session_txt['5.13'];
echo $session_name."<br>";

function do_function ($option){
	switch ($option){
		case "Sent";
			print "Sent";
			break;
		case "Delete";
			print "Deleted";
			break;
		case "Open Mail";
			print "Mail Opened";
			break;
		case "Read Message";
			print "Message Read";
			break;
		case "Reply-to Message";
			print "Reply-to Message";
			break;
	}
}

$mappings = array ( "S" => "Send",
					"D" => "Delete",
					"R" => "Read Message",
					"T" => "Reply-to message");
					
$input = "do something";
do_function ($mappings [strtoupper (substr ($input,0,1))]);

	
$message="
<fieldset><legend><font color=red>TIPS</font></legend>
   strtoupper()轉換為大寫<br>
   substr(\$input,0,1)取字串,從0開始,取1個字元
<br>
</fieldset>
";
echo $message."<br>";