sandm преди 2 години
родител
ревизия
60a1c4d8fe
променени са 2 файла, в които са добавени 72 реда и са изтрити 2 реда
  1. 0 2
      extend/.gitignore
  2. 72 0
      extend/StrUtil.php

+ 0 - 2
extend/.gitignore

@@ -1,2 +0,0 @@
-*
-!.gitignore

+ 72 - 0
extend/StrUtil.php

@@ -0,0 +1,72 @@
+<?php
+
+class StrUtil{
+
+    /**
+     * 判断字符串是否为 NULL 或者为 空白字符串  LiaoYun 2018-06-13
+     * @param str
+     * @return
+     */
+    public static function isEmpOrNull(string $str)
+    {
+        if ($str == null || trim($str) == "") {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    public static function isNotEmpAndNull(string $str)
+    {
+        if ($str == null || trim($str) == "") {
+            return false;
+        } else {
+            return true;
+        }
+    }
+
+    public static function isMoblePhone(String $phone) {
+    	if (self::isEmpOrNull($phone)) {
+    		return false;
+    	}
+        if(!preg_match("/^1[3456789]\d{9}$/",$phone,$res)){
+            return $res;
+        } else {
+            return false;
+        }
+    }
+
+    public static function back(object $obj, string $funName)
+    {
+
+        $jsonStr = json_encode($obj);
+        if (self::isNotEmpAndNull($funName)) {
+            return "<script language='javascript'>parent.{$funName}({$jsonStr})</script>";
+        } else {
+            return "<script language='javascript'>parent.callback({$jsonStr})</script>";
+        }
+
+    }
+
+    /**
+     * 中文乱码转 utf-8, 对页面中 用 encodeURI(encodeURI(url)) 处理过的 url 有效
+     * @return
+     */
+    public static function getRequestDecodeParam($request, $key)
+    {
+        $str = $request[$key];
+        if ($str != null) {
+            try {
+                //解决%和+转码问题
+                $str = preg_replace("/%(?![0-9a-fA-F]{2})/", "%25", $str);
+                $str = preg_replace("/\\+/", "%2B", $str);
+                return trim(urldecode($str));
+            } catch (\Exception $e) {
+                throw new \think\Exception($e->getMessage());
+            }
+        } else {
+            return $str;
+        }
+    }
+
+}