获取随机浮点数

  1. /**
  2. * 获取随机浮点数
  3. * @param $min 最小值
  4. * @param $max 最大值
  5. * @param $num 小数位
  6. * @return string 浮点数
  7. */
  8. public static function randomFloat($min, $max, $num) {
  9. return bcadd($min, bcmul(bcdiv(mt_rand(), mt_getrandmax(), 2), bcsub($max, $min, 0), 2), $num);
  10. }

验证邮箱

  1. /**
  2. * 邮箱验证
  3. * @param $email 邮箱
  4. * @return bool
  5. */
  6. public static function is_email($email){
  7. if(filter_var($email,FILTER_VALIDATE_EMAIL)){
  8. return true;
  9. }else{
  10. return false;
  11. }
  12. }

手机号验证

  1. /**
  2. * 手机号验证
  3. * @param $phone
  4. * @return bool
  5. */
  6. public static function is_phone($phone)
  7. {
  8. if (preg_match("/^1[34578]{1}\d{9}$/", $phone)) {
  9. return true;
  10. } else {
  11. return false;
  12. }
  13. }

手机号星号替换

  1. $num = "13966778888"
  2. $str = substr_replace($num, '****', 3, 4);

数字小写转大写

  1. function num2daxie($num){
  2. $daxie = null;
  3. if(is_numeric($num) && $num >= 0){
  4. $da_num=array('零','一','二','三','四','五','六','七','八','九');
  5. $len_num = strlen($num);
  6. for($i=0;$i<$len_num;$i++){
  7. $daxie.= $da_num[substr($num,$i,1)];
  8. }
  9. }
  10. return $daxie;
  11. }

颜色随机生成

  1. function randomColor() {
  2. $str = '#';
  3. for($i = 0 ; $i < 6 ; $i++) {
  4. $randNum = rand(0 , 15);
  5. switch ($randNum) {
  6. case 10: $randNum = 'A'; break;
  7. case 11: $randNum = 'B'; break;
  8. case 12: $randNum = 'C'; break;
  9. case 13: $randNum = 'D'; break;
  10. case 14: $randNum = 'E'; break;
  11. case 15: $randNum = 'F'; break;
  12. }
  13. $str .= $randNum;
  14. }
  15. return $str;
  16. }
  17. $color = randomColor();