快取指令
php註解
<?php
// 這裡是單行 PHP 註解 ...
// 這裡是單行 PHP 註解 ...
?>
<?php
/*
...這裡是多行 PHP 註解
...這裡是多行 PHP 註解
...這裡是多行 PHP 註解
*/
?>
<font size="1" color="blue">這是大小為 1 的文字</font><br>
<a href="/html/image-img-tag.html">這個連結</a>會連到 Fooish 圖片標籤教學頁面
<a href="#" style="color:red;" target="屬性" rel="屬性">修改超連結顏色為紅色</a>
修改超連結顏色方法二、另外寫 CSS 來修改,全網頁
<style>
a {
color:green;
}
</style>
<a href="#">修改超連結顏色為綠色</a>
<table backgroun="" border"1" width="" height="" align="center" valign=""><tr><td align="" colspan="" rowspan="">
<DIV style="background-color:#C7FF91;width:300px;height:100px;text-align:center;line-height:100px;">
測試文字垂直置中
</DIV>
<a> 標籤的屬性 (attributes)
href
指定一個 URL 看連結要連到哪邊,亦可以用target指向相對位址。
target
target 有下面這些屬性值:
_self: 預設值,在當前視窗開啟
_blank: 在新視窗開啟
_parent: 在上一層父視窗開啟
_top: 在最頂層父視窗開啟
framename: 指定在哪個框架中開啟
錨定連結
rel屬性
nofollow:不要追蹤跟索引
external:等效於target="_blank",但_blank在xhtml會失效
noopener:等效於target="_blank",但可以避免window.opener.location = newURL的攻擊
noreferrer:安全設定,會跟noopener一起使用。ex:<a href=url" rel ="noreferrer noopener" target="_blank"></a>
備註:noreferrer和noopener屬性值針對瀏覽器,對SEO優化沒有任何影響
跳往同頁面不同區塊的位置
使用方法:
<a href="#some-section-id">連結文字</a>
上面的連結點擊後會跳去 id="some-section-id" 的 HTML 元素區塊。
例如跳到這邊:
<div id="some-section-id">
hello
</div>
圖片連結
<a href="https://example.com/" target="_blank">
<img src="https://source.unsplash.com/WLUHO9A_xik/600x400">
</a>
電子郵件超連結 mailto:
<a href="mailto:電子郵件信箱">連絡信箱</a>
電話號碼連結 tel: **遵循 RFC 3966 標準格式**
<a href="#" style="color:red;">修改超連結顏色為紅色</a>
<a href="tel:電話號碼">連結文字</a>
<marquee>跑馬燈</marquee>
direction="參數值":控制跑的方向,上下左右分別為 up、dun、left、right
align="參數值":控制對齊方式,向上對齊 top、垂直至中 midden、向下對齊 botton
scrollamount="參數值":跑馬燈的速度,數字越大表示跑得越快
height="參數值":區域高度
width="參數值":區域寬度
behavior="參數值":跑馬燈的行為模式,來回跑用 alternate、跑入就停止用 slide
bgcolor="參數值":設定跑馬燈的背影顏色,預設為透明
Loop="輪播次數"
Behavior"輪播方式" 設 "Scroll"(內定值)、"Slide" 當文字碰到左邊就會停止、"Alternate" 在左右兩邊彈來彈去。
"
scrolldelay="0" 振動效果
(空白鍵字符) (半中文字型空白鍵字符) (一中文字型空白鍵字符)
onMouseOver="this.stop()" onMouseOut="this.start()" 滑鼠放在上方就停止
hspace="" 左右外框
vspace="" 上下外框
半形的不換行空格,就是一般鍵盤上的空白鍵(space key)產生的空格
 
半形的空格,特性為寬度是 1/2 個中文字寬度
 
全形的空格,特性係寬度是 1 個中文字寬度
時間相關
使用 date() 函式獲取 PHP 的當前年份
使用 strftime() 函式獲取 PHP 的當前年份
使用 DateTime 物件獲取 PHP 的當前年份
<?php
$Date = date("d-m-Y");
echo "The current date is $Date.";
echo "\n";
$Year = date("Y");
echo "The current year is $Year.";
echo "\n";
$Year2 = date("y");
echo "The current year in two digits is $Year2.";
?>
The current date is 20-04-2020.
The current year is 2020.
The current year in two digits is 20.
<?php
$Date = strftime("%d-%m-%Y");
echo "The current date is $Date.";
echo "\n";
$Year = strftime("%Y");
echo "The current year is $Year.";
echo "\n";
$Year2 = strftime("%y");
echo "The current year in two digits is $Year2.";
?>
The current date is 20-04-2020.
The current year is 2020.
The current year in two digits is 20.
<?php
$Object = new DateTime();
$Date = $Object->format("d-m-Y");
echo "The current date is $Date.";
echo "\n";
$Year = $Object->format("Y");
echo "The current year is $Year.";
echo "\n";
$Year2 = $Object->format("y");
echo "The current year in two digits is $Year2.";
?>
The current date is 20-04-2020.
The current year is 2020.
The current year in two digits is 20.
找出每個月的最後一天
$L = new DateTime( '2020-02-01' );
echo $L->format( 'Y-m-t' );
使用 PHP 5.3 及更高版本中的 DateTime() 和 DateInterval() 的物件
計算出2天的差
PHP >5.3
$firstDate = new DateTime("2019-01-01");
$secondDate = new DateTime("2020-03-04");
$intvl = $firstDate->diff($secondDate);
echo $intvl->y . " year, " . $intvl->m." months and ".$intvl->d." day";
echo "<br>";
// Total amount of days
echo $intvl->days . " days ";
//output: 1 year, 2 months and 1 day
// 428 days
將時間更換成可以讀取的日期時間
date($format, $timestamp);
<?php
$date = date('d-m-Y H:i:s', 1565600000);
echo "The date is $date.";
?>
這裡的日期格式為 d-m-Y - 日-月-年,時間格式為 H:i:s - 小時:分鐘:秒。
輸出:The date and time are 12-08-2019 08:53:20.
$datetimeObject->setTimestamp($timestamp);
示例程式碼:
<?php
$date = new DateTime();
$date->setTimestamp(1565600000);
$variable = $date->format('U = d-m-Y H:i:s');
echo "The date and time is $variable.";
?>
輸出:The date and time are 1565600000 = 12-08-2019 08:53:20.
DateTime::createFromFormat($format, $time, $timezone);
變數 $format 是日期的格式,變數 $time 是字串中給出的時間,變數 $timezone 表示時區。前兩個引數是必需引數。
<?php
// Calling the createFromFormat() function
$datetime = DateTime::createFromFormat('U', '1565600000');
// Getting the new formatted datetime
$date= $datetime->format('d-m-Y H:i:s');
echo "The date and time is $date.";
?>
格式 d-m-Y H:i:s 顯示日期和時間。
輸出:The date and time are 12-08-2019 08:53:20.
PHP sprintf() 函数
sprintf(format,arg1,arg2,arg++)
%% - 返回百分比符號
%b - 二進制數
%c - 依照 ASCII 值的字符
%d - 帶符號十進制數
%e - 可續計數法(比如 1.5e+3)
%u - 無符號十進制數
%f - 浮點數(local settings aware)
%F - 浮點數(not local settings aware)
%o - 八進制數
%s - 字符串
%x - 十六進制數(小寫字母)
%X - 十六進制數(大寫字母)
例子 1
<?php
$str = "Hello";
$number = 123;
$txt = sprintf("%s world. Day number %u",$str,$number);
echo $txt;
?>
輸出:Hello world. Day number 123
例子 2
<?php
$number = 123;
$txt = sprintf("%f",$number);
echo $txt;
?>
輸出:123.000000
例子 3
<?php
$number = 123;
$txt = sprintf("With 2 decimals: %1$.2f<br />With no decimals: %1$u",$number);
echo $txt;
?>
輸出:With 2 decimals: 123.00
With no decimals: 123
改為偵錯模式
到php.ini 將display_errors = on