PHP
  • Introduction
  • PHPMailer
  • UploadFile
  • PHP link MySQL to insert
  • rand功能
  • Create GUID by random
  • Coding problem
  • PHP+MySQL樹狀圖
  • JWT(Json Web Token)
  • 小功能
    • array_push
    • array_chunk
  • 遞迴
  • 生成json
  • 註解方式
  • Call API
  • google url shortener
  • 身分證字號驗證
  • google maps api 取兩點路線規劃的距離
  • 兩點座標的直線距離
  • 將傳入的陣列重新根據某個欄位做排序
  • 抓取最準的IP,從近到遠做判斷
  • 利用curl推播ios,用ios的token
  • 在local端onServer
Powered by GitBook
On this page
  • 當沒有的時候就自己生
  • 產出

Was this helpful?

Create GUID by random

當沒有的時候就自己生

產出

直接貼上function

/**
 * 取得隨機GUID字串, 依「$havedash」決定是否包含Dash
 * @param type $havedash 是否包含Dash
 * @return type GUID字串
 */
public static function CreateGUID($havedash) {

  if ($havedash) {
    $formatstring = '%04x%04x-%04x-%04x-%04x-%04x%04x%04x';
  } else {
    $formatstring = '%04x%04x%04x%04x%04x%04x%04x%04x';
  }

  return sprintf($formatstring,
          // 32 bits for "time_low"
          mt_rand(0, 0xffff), mt_rand(0, 0xffff),
          // 16 bits for "time_mid"
          mt_rand(0, 0xffff),
          // 16 bits for "time_hi_and_version",
          // four most significant bits holds version number 4
          mt_rand(0, 0x0fff) | 0x4000,
          // 16 bits, 8 bits for "clk_seq_hi_res",
          // 8 bits for "clk_seq_low",
          // two most significant bits holds zero and one for variant DCE1.1
          mt_rand(0, 0x3fff) | 0x8000,
          // 48 bits for "node"
          mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
  );
}
Previousrand功能NextCoding problem

Last updated 5 years ago

Was this helpful?