PageRenderTime 51ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/php/func.php

https://github.com/satup/WhatsAPI
PHP | 47 lines | 39 code | 8 blank | 0 comment | 4 complexity | 1d2b3afef70b0c878382e7f6cf5d67fe MD5 | raw file
  1. <?php
  2. function isShort($str){
  3. $len = strlen($str);
  4. if($len < 256)$res = true;
  5. else $res = false;
  6. return $res;
  7. }
  8. function strlen_wa($str){
  9. $len = strlen($str);
  10. if($len >= 256)$len = $len&0xFF00 >> 8;
  11. return $len;
  12. }
  13. function _hex($int){
  14. return (strlen(sprintf("%X", $int))%2==0) ? sprintf("%X", $int) : sprintf("0%X", $int);
  15. }
  16. function random_uuid(){
  17. return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
  18. mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),
  19. mt_rand( 0, 0xffff ),
  20. mt_rand( 0, 0x0fff ) | 0x4000,
  21. mt_rand( 0, 0x3fff ) | 0x8000,
  22. mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff )
  23. );
  24. }
  25. function strtohex($str){
  26. $hex = '';
  27. for ($i=0; $i < strlen($str); $i++)$hex .= "\x".dechex(ord($str[$i]));
  28. return $hex;
  29. }
  30. function startsWith($haystack, $needle , $pos=0){
  31. $length = strlen($needle);
  32. return (substr($haystack, $pos, $length) === $needle);
  33. }
  34. function endsWith($haystack, $needle){
  35. $length = strlen($needle);
  36. $start = $length * -1;
  37. return (substr($haystack, $start) === $needle);
  38. }
  39. ?>