程式 | <? $x=-50; $a=abs($x); echo "|".$x."|=".$a; ?> |
<? $x=-3.14; $a=abs($x); echo "|".$x."|=".$a; ?> |
<? $x=1.23e-5; $a=abs($x); echo "|".$x."|=".$a; ?> |
結果 | |-50|=50 | |-3.14|=3.14 | |1.23E-5|=1.23E-5 |
deg2rad(角度) | rad2deg(弧度) | π | |
程式 | <? $deg=30; $rad=deg2rad($deg); echo $deg."°=".$rad."弧度"; ?> |
<? $rad=1; $deg=rad2deg($rad); echo $rad."弧度=".$deg."°"; ?> |
<? echo "π≒".pi(); ?> |
結果 | 30°=0.5235987755983弧度 | 1弧度=57.295779513082° | π≒3.1415926535898 |
程式 | 結果 |
<? $arg=30°; $rad=deg2rad($arg); echo "sin(".$arg.")=".sin($rad); echo "<br>cos(".$arg.")=".cos($rad); echo "<br>tan(".$arg.")=".tan($rad); ?> |
sin(30°)=0.5 cos(30°)=0.86602540378444 tan(30°)=0.57735026918963 |
程式 | <? $val=1; echo "sin<sup>-1</sup>(".$val.")=".asin($val)."弧度=".rad2deg(asin($val))."°"; echo "<br>cos<sup>-1</sup>(".$val.")=".acos($val)."弧度=".rad2deg(acos($val))."°"; echo "<br>tan<sup>-1</sup>(".$val.")=".atan($val)."弧度=".rad2deg(atan($val))."°"; ?> |
結果 | sin-1(1)=1.5707963267949弧度=90° cos-1(1)=0弧度=0° tan-1(1)=0.78539816339745弧度=45° |
程式 | <? echo pow(2,4); ?> |
<? echo pow(2,0.5); ?> |
<? echo pow(2,1/2); ?> |
<? echo pow(2,-2); ?> |
結果 | 16 | 1.4142135623731 | 1.4142135623731 | 0.25 |
程式 | <? echo log10(2); ?> |
<? echo log10(0); ?> |
<? echo log10(-1); ?> |
結果 | 0.30102999566398 | -INF | NAN |
程式 | <? echo round(pi(),3); ?> |
<? echo round(pi(),0); ?> |
<? echo round(pi(),-1); ?> |
結果 | 3.142 | 3 | 0 |
程式 | <? echo floor(3.14); ?> |
<? echo floor(0); ?> |
<? echo floor(-1.2); ?> |
結果 | 3 | 0 | -2 |
程式 | <? echo ceil(3.14); ?> |
<? echo ceil(0); ?> |
<? echo ceil(-1.2); ?> |
結果 | 4 | 0 | -1 |
程式 | <? echo sqrt(9); ?> |
<? echo sqrt(2); ?> |
<? echo sqrt(0); ?> |
<? echo sqrt(-1); ?> |
結果 | 3 | 1.4142135623731 | 0 | NAN |
程式 | <? echo rand(1,5); ?> |
<? echo rand(-5,5); ?> |
<? echo rand(1,1); ?> |
結果 | 2 | 0 | 1 |
程式 | <? echo $REMOTE_ADDR; ?> |
<? echo $REMOTE_HOST; ?> |
結果 |
程式 | <? if(isset($REMOTE_HOST)) echo $REMOTE_HOST; else echo $REMOTE_ADDR; ?> |
結果 |
程式 | <? echo gethostbyaddr($REMOTE_ADDR); ?> |
結果 | Warning: gethostbyaddr(): Address is not a valid IPv4 or IPv6 address in /volume1/homes/rick/www/homepage/phpfunction.php3 on line 427 |
程式 | <form method=post action=mailtest.php target=_blank> 您將發信給:rick@pc08.ccsh.tp.edu.tw<BR> 您的E-Mail:<input type=text name=from><BR> 信件主旨:<input type=test name=subject><BR> 信件內容:<textarea name=message rows=10 cols=30></textarea> <BR> <input type=SUBMIT value=確定> <input type=RESET value=清除> </form> mailtest.php |
結果 |
程式 | 結果 |
<? echo time(); ?> |
1726614293 |
引數格式 | 意義 | 程式 | 結果 |
a | 顯示現在時間am或pm | <? echo date(a); ?> |
Warning: Use of undefined constant a - assumed 'a' (this will throw an Error in a future version of PHP) in /volume1/homes/rick/www/homepage/phpfunction.php3 on line 502 am |
A | 顯示現在時間AM或PM | <? echo date(A); ?> |
Warning: Use of undefined constant A - assumed 'A' (this will throw an Error in a future version of PHP) in /volume1/homes/rick/www/homepage/phpfunction.php3 on line 512 AM |
y | 以2位數字顯示西元年份 | <? echo date(y); ?> |
Warning: Use of undefined constant y - assumed 'y' (this will throw an Error in a future version of PHP) in /volume1/homes/rick/www/homepage/phpfunction.php3 on line 522 24 |
Y | 以4位數字顯示西元年份 | <? echo date(Y); ?> |
Warning: Use of undefined constant Y - assumed 'Y' (this will throw an Error in a future version of PHP) in /volume1/homes/rick/www/homepage/phpfunction.php3 on line 532 2024 |
m | 以2位數字顯示月份 | <? echo date(m); ?> |
Warning: Use of undefined constant m - assumed 'm' (this will throw an Error in a future version of PHP) in /volume1/homes/rick/www/homepage/phpfunction.php3 on line 542 09 |
n | 顯示月份 | <? echo date(n); ?> |
Warning: Use of undefined constant n - assumed 'n' (this will throw an Error in a future version of PHP) in /volume1/homes/rick/www/homepage/phpfunction.php3 on line 552 9 |
F | 以英文字顯示月份 | <? echo date(F); ?> |
Warning: Use of undefined constant F - assumed 'F' (this will throw an Error in a future version of PHP) in /volume1/homes/rick/www/homepage/phpfunction.php3 on line 562 September |
M | 以3位英 文字顯示月份 | <? echo date(M); ?> |
Warning: Use of undefined constant M - assumed 'M' (this will throw an Error in a future version of PHP) in /volume1/homes/rick/www/homepage/phpfunction.php3 on line 572 Sep |
j | 顯示日期 | <? echo date(j); ?> |
Warning: Use of undefined constant j - assumed 'j' (this will throw an Error in a future version of PHP) in /volume1/homes/rick/www/homepage/phpfunction.php3 on line 582 18 |
d | 以2位數字顯示日期 | <? echo date(d); ?> |
Warning: Use of undefined constant d - assumed 'd' (this will throw an Error in a future version of PHP) in /volume1/homes/rick/www/homepage/phpfunction.php3 on line 592 18 |
w | 以數字顯示星期幾 (0--星期日‧‧‧6--星期六) |
<? echo date(w); ?> |
Warning: Use of undefined constant w - assumed 'w' (this will throw an Error in a future version of PHP) in /volume1/homes/rick/www/homepage/phpfunction.php3 on line 603 3 |
l | 以英文字顯示星期 | <? echo date(l); ?> |
Warning: Use of undefined constant l - assumed 'l' (this will throw an Error in a future version of PHP) in /volume1/homes/rick/www/homepage/phpfunction.php3 on line 613 Wednesday |
D | 以3位英文字顯示星期 | <? echo date(D); ?> |
Warning: Use of undefined constant D - assumed 'D' (this will throw an Error in a future version of PHP) in /volume1/homes/rick/www/homepage/phpfunction.php3 on line 623 Wed |
h | 以2位數字顯示12小時制的時 | <? echo date(h); ?> |
Warning: Use of undefined constant h - assumed 'h' (this will throw an Error in a future version of PHP) in /volume1/homes/rick/www/homepage/phpfunction.php3 on line 633 07 |
g | 顯示12小時制的時 | <? echo date(g); ?> |
Warning: Use of undefined constant g - assumed 'g' (this will throw an Error in a future version of PHP) in /volume1/homes/rick/www/homepage/phpfunction.php3 on line 643 7 |
H | 以2位數字顯示24小時制的時 | <? echo date(H); ?> |
Warning: Use of undefined constant H - assumed 'H' (this will throw an Error in a future version of PHP) in /volume1/homes/rick/www/homepage/phpfunction.php3 on line 653 07 |
G | 顯示24小時制的時 | <? echo date(G); ?> |
Warning: Use of undefined constant G - assumed 'G' (this will throw an Error in a future version of PHP) in /volume1/homes/rick/www/homepage/phpfunction.php3 on line 663 7 |
i | 以2位數字顯示分 | <? echo date(i); ?> |
Warning: Use of undefined constant i - assumed 'i' (this will throw an Error in a future version of PHP) in /volume1/homes/rick/www/homepage/phpfunction.php3 on line 673 04 |
s | 顯示秒數 | <? echo date(s); ?> |
Warning: Use of undefined constant s - assumed 's' (this will throw an Error in a future version of PHP) in /volume1/homes/rick/www/homepage/phpfunction.php3 on line 683 53 |
L | 顯示該年是否為閏年 (1--閏年;0--平年) |
<? echo date(L); ?> |
Warning: Use of undefined constant L - assumed 'L' (this will throw an Error in a future version of PHP) in /volume1/homes/rick/www/homepage/phpfunction.php3 on line 694 1 |
t | 顯示該月份有幾天 | <? echo date(t); ?> |
Warning: Use of undefined constant t - assumed 't' (this will throw an Error in a future version of PHP) in /volume1/homes/rick/www/homepage/phpfunction.php3 on line 704 30 |
U | 自GMT1970年1月1日0時0分0秒 至現在的秒數(同time()函式) |
<? echo date(U); ?> |
Warning: Use of undefined constant U - assumed 'U' (this will throw an Error in a future version of PHP) in /volume1/homes/rick/www/homepage/phpfunction.php3 on line 715 1726614293 |
z | 顯示一年的第幾天 | <? echo date(z); ?> |
Warning: Use of undefined constant z - assumed 'z' (this will throw an Error in a future version of PHP) in /volume1/homes/rick/www/homepage/phpfunction.php3 on line 725 261 |
陣列索引 | 意義 | 程式 | 結果 |
year | 以4位數字顯示西元年份 | <? $d=getdate(); echo $d[year]; ?> |
Warning: Use of undefined constant year - assumed 'year' (this will throw an Error in a future version of PHP) in /volume1/homes/rick/www/homepage/phpfunction.php3 on line 747 2024 |
mon | 以2位數字顯示月份 | <? $d=getdate(); echo $d[mon]; ?> |
Warning: Use of undefined constant mon - assumed 'mon' (this will throw an Error in a future version of PHP) in /volume1/homes/rick/www/homepage/phpfunction.php3 on line 759 9 |
month | 以英文字顯示月份 | <? $d=getdate(); echo $d[month]; ?> |
Warning: Use of undefined constant month - assumed 'month' (this will throw an Error in a future version of PHP) in /volume1/homes/rick/www/homepage/phpfunction.php3 on line 771 September |
mday | 以數字顯示日 | <? $d=getdate(); echo $d[mday]; ?> |
Warning: Use of undefined constant mday - assumed 'mday' (this will throw an Error in a future version of PHP) in /volume1/homes/rick/www/homepage/phpfunction.php3 on line 783 18 |
wday | 以數字顯示星期 | <? $d=getdate(); echo $d[wday]; ?> |
Warning: Use of undefined constant wday - assumed 'wday' (this will throw an Error in a future version of PHP) in /volume1/homes/rick/www/homepage/phpfunction.php3 on line 795 3 |
weekday | 以英文字顯示星期 | <? $d=getdate(); echo $d[weekday]; ?> |
Warning: Use of undefined constant weekday - assumed 'weekday' (this will throw an Error in a future version of PHP) in /volume1/homes/rick/www/homepage/phpfunction.php3 on line 807 Wednesday |
hours | 以數字顯示時 | <? $d=getdate(); echo $d[hours]; ?> |
Warning: Use of undefined constant hours - assumed 'hours' (this will throw an Error in a future version of PHP) in /volume1/homes/rick/www/homepage/phpfunction.php3 on line 819 7 |
minutes | 以數字顯示分 | <? $d=getdate(); echo $d[minuts]; ?> |
Warning: Use of undefined constant minutes - assumed 'minutes' (this will throw an Error in a future version of PHP) in /volume1/homes/rick/www/homepage/phpfunction.php3 on line 831 4 |
seconds | 以數字顯示秒 | <? $d=getdate(); echo $d[seconds]; ?> |
Warning: Use of undefined constant seconds - assumed 'seconds' (this will throw an Error in a future version of PHP) in /volume1/homes/rick/www/homepage/phpfunction.php3 on line 843 53 |
程式 | 結果 |
<form method=post action=checkdate.php3 target=_blank> 請輸入日期:<BR>西元 <input type=text size=4 name=year>年 <input type=text size=2 name=month>月 <input type=text size=2 name=day>日<BR> <input type=SUBMIT value=確定> <input type=RESET value=清除> </form> checkdate.php3 |
程式 | 結果 |
<? //副程式 function permutation($n,$m) { $per=1; for($i=$n;$i>($n-$m);$i--) { $per=$per*$i; } return $per; } //主程式 $p1=permutation(3,1); $p2=permutation(3,2); $p3=permutation(3,3); echo "P<sub>1</sub><sup>3</sup>=".$p1; echo "<BR>P<sub>2</sub><sup>3</sup>=".$p2; echo "<BR>P<sub>3</sub><sup>3</sup>=".$p3; ?> |
P13=3 P23=6 P33=6 |
程式 | 結果 |
//主程式 <? include ( "combination.php3"); $c1=combination(3,1); $c2=combination(3,2); $c3=combination(3,3); echo "C<sub>1</sub><sup>3</sup>=".$c1; echo "<BR>C<sub>2</sub><sup>3</sup>=".$c2; echo "<BR>C<sub>3</sub><sup>3</sup>=".$c3; ?>
//副程式combination.php3 |
C13=3 C23=3 C33=1 |
By Rick 2003