[php_Shell]-sample01
[php_Shell]-sample01
GITHUB: https://github.com/jash-git/php_Shell
功能說明:
01.利用PHP建立專屬的SHELL函式庫
02.實作log檔案函數與實測
檔案功能說明:
01.利用PHP建立自己常用函式庫(lib.php)
02.建立主要執行的PHP檔案(main.php)
03.建立執行的SHELL檔案(run.bat)
檔案內容:
01-lib.php
<?php //jashlib.php function Printf_n($string)//單純文字輸出換行 { echo ‘php out:’.$string.”\n”; } function SWAP(&$a,&$b)//透過位址方式交換兩數 { $c=$a; $a=$b; $b=$c; } $fp; function OpenLogFile($FileName) { global $fp; $fp=fopen($FileName,”w”);//$fp=fopen($FileName,”a+”); } function WriteLog($FileName,$Position,$Message) { //WriteLog(__FILE__,__LINE__,”Message”); global $fp; fprintf($fp,”%s,%d-%s\n”,$FileName,$Position,$Message); } function CloseLogFile() { global $fp; fclose($fp); } ?> |
02-main.php
<?php header(‘content-type:text/html;charset=utf-8’); //test.php include(“lib.php”);//引用函式庫 OpenLogFile(“logtest.txt”); $a=10;$b=20; Printf_n(“ouput message on UI”); WriteLog(__FILE__,__LINE__,”未呼叫SWAP函數前a=”.$a.” b=”.$b); WriteLog(__FILE__,__LINE__,”未呼叫SWAP函數前”); SWAP($a,$b); WriteLog(__FILE__,__LINE__,”呼叫SWAP函數後”); WriteLog(__FILE__,__LINE__,”呼叫SWAP函數後a=”.$a.” b=”.$b); ?> |
03-run.bat
..\Tool\php.exe .\main.php pause |