common.php 640 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. // 应用公共文件
  3. function validateEmail($email): bool
  4. {
  5. if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  6. return false;
  7. } else {
  8. return true;
  9. }
  10. }
  11. function uuid(): string
  12. {
  13. $chars = md5(uniqid(mt_rand(), true));
  14. return substr($chars, 0, 8) . '-'
  15. . substr($chars, 8, 4) . '-'
  16. . substr($chars, 12, 4) . '-'
  17. . substr($chars, 16, 4) . '-'
  18. . substr($chars, 20, 12);
  19. }
  20. function renderToken($t = 'tab'): string
  21. {
  22. $s = uuid() . strval(time()) . $t;
  23. return md5($s);
  24. }
  25. function joinPath($path1, $path2)
  26. {
  27. return preg_replace("#//#", "/", $path1 . $path2);
  28. }