[……]
分類: PHP
NTP Server static 狀態速查
NTP Server Taiwan 網路時間協定伺服器
台灣國家時間與頻率標準實驗室 – NTP Server
參考:http://ww.stdtime.gov.tw/Time/ntp/resource.htm
Google – NTP Server
參考:https://developers.google.com/time/
Apple – NTP Server
微軟Microsoft – NTP Server
Facebook – NTP Server
參考:https://engineering.fb.com/production-engineering/ntp-service/
[……]
IPv4 及 IPv6 最大字串長度
IPv4 address Max string Length
12個數字+3個分隔符=15個字符。
IPv6 address Max string Length
32個十六進制數字+ 7個分隔符= 39個字符。
包含保留映射IPv6地址的IPv4地址 = 45個字符
參考
https://stackoverflow.com/questions/1076714/max-length-for-client-ip-address/7477384#7477384
[……]
PHP Cookie 儲存陣列資料
有個陣列,希望將陣列儲存至 Cookie 中,這裡提供兩種方法
在官網的範例中,可用下方的方式達成目的
https://www.php.net/manual/en/function.setcookie.php
output:
雖然是達到目的了,但事實上是建立了三個Cookie,怎麼看都不優雅,更難想像若是一個複雜的多惟陣列,會產生多少Cookie
再來介紹一個比較優雅的做法,我也比較喜歡,先將陣列序列化成字串存入Cookie
需要用到的時候,再將字串反序列化,是不是方便多了呢
output:
[……]
PHP get start date 00:00:00 – end date 23:59:59
最近一個月至今:
Output:
最近一周 至今 :
上一周:
上個月初至月底:
上周一至週日:
參考
https://stackoverflow.com/questions/5212282/strtotime-a-second-before-midnight
[……]
PHP new a Class with a string
PHP array_merge do not reset index
array_merge 用來進行2個或多個陣列合併
輸出結果:
輸出出結果,陣列的索引重新排序了。某些情況陣列的索引與值是有關聯的,這麼做丟失索引及值的關聯,目前 array_merge 並沒有是否重建索引的選項,所以要透過另外一種方式來合併陣列,並保持索引鍵與值的關聯。
透過下面的代碼實現:
輸出結果:
就這樣,用運算符「+」來進行陣列的累加,非常簡單,且保持 鍵與值的關聯。
請注意型態必須都為 array
但也不必太擔心,型態錯誤會報錯
[……]
PHP number convert to Excel column letters 2
本篇提供兩個方法互轉,簡潔又好用,沒有限制數字大小
繼下面這篇文章後,我發現更簡短的方法,提供給大家參考
數字轉換 Excel 欄位英文字母
ex:
Excel 欄位英文字母轉換回 數字
ex:
[……]
PHP number convert to Excel column letters
數字轉換 Excel 欄位英文字母,例如 1 = A , 2 = B , 27 = AA
Excel 欄位英文字母轉換回 數字 , 例如 A = 1 , B = 2 , AA = 27
本篇提供兩個方法互轉,簡潔又好用,沒有限制數字大小
數字轉換 Excel 欄位英文字母
ex:
Excel 欄位英文字母轉換回 數字
ex:
https://stackoverflow.com/a/25214690/6784662
我發現一個更簡潔的方法
[……]