checkChajian.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. /**
  3. * 字符检查插件
  4. */
  5. class checkChajian extends Chajian{
  6. /**
  7. * 是否为邮箱
  8. */
  9. public function isemail($str)
  10. {
  11. if(isempt($str))return false;
  12. return filter_var($str, FILTER_VALIDATE_EMAIL);
  13. }
  14. /**
  15. * 是否为手机号
  16. */
  17. public function ismobile($str)
  18. {
  19. if(isempt($str))return false;
  20. if(!is_numeric($str) || strlen($str)<5)return false;
  21. return true;
  22. }
  23. /**
  24. * 判断是否为国内手机号
  25. */
  26. public function iscnmobile($str)
  27. {
  28. if(isempt($str))return false;
  29. if(!is_numeric($str) || strlen($str)!=11)return false;
  30. if(!preg_match("/1[3458769]{1}\d{9}$/", $str))return false;
  31. return true;
  32. }
  33. /**
  34. * 是否有中文
  35. */
  36. public function isincn($str)
  37. {
  38. return preg_match("/[\x7f-\xff]/", $str);
  39. }
  40. //是否整个的英文a-z,0-9
  41. public function iszgen($str)
  42. {
  43. if(isempt($str))return false;
  44. if($this->isincn($str)){
  45. return false;
  46. }
  47. return true;
  48. }
  49. //返回字符串编码
  50. public function getencode($str)
  51. {
  52. $encode = mb_detect_encoding($str, array('ASCII','UTF-8','GB2312','GBK','BIG5'));
  53. $encode = strtolower($encode);
  54. return $encode;
  55. }
  56. /**
  57. * 是否为数字
  58. */
  59. public function isnumber($str)
  60. {
  61. if(isempt($str))return false;
  62. return is_numeric($str);
  63. }
  64. /**
  65. * 字符是否包含数字
  66. */
  67. public function isinnumber($str)
  68. {
  69. return preg_match("/[0-9]/", $str);
  70. }
  71. /**
  72. * 是否为日期
  73. */
  74. public function isdate($str)
  75. {
  76. return preg_match("/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/", $str);
  77. }
  78. /**
  79. * 是否为日期时间
  80. */
  81. public function isdatetime($str)
  82. {
  83. return preg_match("/^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$/", $str);
  84. }
  85. /**
  86. * 是否为月份
  87. */
  88. public function ismonth($str)
  89. {
  90. return preg_match("/^([0-9]{4})-([0-9]{2})$/", $str);
  91. }
  92. /**
  93. * 过滤字母,只留数字
  94. */
  95. public function onlynumber($str)
  96. {
  97. return preg_replace('/[a-zA-Z]/','', $str);
  98. }
  99. /**
  100. * 仅支持0-9A-Za-z - |
  101. * return boolean
  102. */
  103. public function onlynoen($str)
  104. {
  105. $str1 = ''.$str.'';
  106. $bobg = preg_replace("/[a-zA-Z0-9_]/",'', $str1);
  107. $bobg = str_replace(array('-','|'),'', $bobg);
  108. return $bobg;
  109. }
  110. /**
  111. * 替换空格
  112. */
  113. public function replacekg($str)
  114. {
  115. $str = preg_replace('/\s*/', '', $str);
  116. $qian = array(" "," ","\t","\n","\r");
  117. return str_replace($qian, '', $str);
  118. }
  119. public function removeEmojiChar($str)
  120. {
  121. $mbLen = mb_strlen($str);
  122. $strArr = array();
  123. for ($i = 0; $i < $mbLen; $i++) {
  124. $mbSubstr = mb_substr($str, $i, 1, 'utf-8');
  125. if (strlen($mbSubstr) >= 4) {
  126. continue;
  127. }
  128. $strArr[] = $mbSubstr;
  129. }
  130. return implode('', $strArr);
  131. }
  132. /**
  133. * 判断是不是内网地址
  134. */
  135. public function isneiurl($str)
  136. {
  137. $strt = strtolower($str);
  138. $strt = str_replace($strt, 'https:', 'http:');
  139. $nearr= array('localhost','127.0.0','192.','10.','172.');
  140. $bool = false;
  141. foreach($nearr as $ip){
  142. if(contain($str, 'http://'.$ip.'')){
  143. $bool = true;
  144. break;
  145. }
  146. }
  147. return $bool;
  148. }
  149. /**
  150. * 过滤sql的
  151. */
  152. public function onlysql($str)
  153. {
  154. $str = $this->rock->iconvsql($str);
  155. $str = str_replace('(','(', $str);
  156. $str = str_replace(')',')', $str);
  157. $str = str_replace(',',',', $str);
  158. return $str;
  159. }
  160. }
粤ICP备19079148号