Util.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * Class Util
  4. *
  5. * @filesource Util.php
  6. * @created 25.11.2015
  7. * @package chillerlan\QRCode
  8. * @author Smiley <smiley@chillerlan.net>
  9. * @copyright 2015 Smiley
  10. * @license MIT
  11. */
  12. namespace chillerlan\QRCode;
  13. /**
  14. *
  15. */
  16. class Util{
  17. /**
  18. * @param string $s
  19. *
  20. * @return bool
  21. */
  22. public static function isNumber($s){
  23. $len = strlen($s);
  24. for($i = 0; $i < $len; $i++){
  25. $c = ord($s[$i]);
  26. if(!(ord('0') <= $c && $c <= ord('9'))){
  27. return false;
  28. }
  29. }
  30. return true;
  31. }
  32. /**
  33. * @param string $s
  34. *
  35. * @return bool
  36. */
  37. public static function isAlphaNum($s){
  38. $len = strlen($s);
  39. for($i = 0; $i < $len; $i++){
  40. $c = ord($s[$i]);
  41. if(!(ord('0') <= $c && $c <= ord('9')) && !(ord('A') <= $c && $c <= ord('Z')) && strpos(' $%*+-./:', $s[$i]) === false){
  42. return false;
  43. }
  44. }
  45. return true;
  46. }
  47. /**
  48. * @param string $s
  49. *
  50. * @return bool
  51. */
  52. public static function isKanji($s){
  53. $i = 0;
  54. $len = strlen($s);
  55. while($i + 1 < $len){
  56. $c = ((0xff&ord($s[$i])) << 8)|(0xff&ord($s[$i + 1]));
  57. if(!(0x8140 <= $c && $c <= 0x9FFC) && !(0xE040 <= $c && $c <= 0xEBBF)){
  58. return false;
  59. }
  60. $i += 2;
  61. }
  62. if($i < $len){
  63. return false;
  64. }
  65. return true;
  66. }
  67. }