<? Php /** * Common static classes. Here we mainly sort out some methods that PHP often uses. * * @ Author ZCStrong-youkuiyuan */ Class C { /* * Built-in parameters for private random number processing * Array random number array/param random number length * Returns a random number. */ Static private function Random ($ array, $ param ){ $ RandArray = $ array; $ RandCount = count ($ randArray ); $ Num = intval ($ param ); $ ResultStr = ""; For ($ I = 0; $ I <$ num; $ I ++ ){ $ ResultStr. = $ randArray [rand (0, intval ($ randCount)-1)]; } Return $ resultStr; } // Random number (number type) Static public function Randnum ($ param = 8 ){ $ RandArray = str_split ("1234567890 "); $ ResultStr = C: Random ($ randArray, $ param ); Return $ resultStr; } // Random number (Mixed Type)-None Static public function RandStr ($ param = 8, $ capslock = FALSE ){ $ RandArray = str_split ("abcdefghijklmnopqrstuvwxyz123456789ABCDEFGHIGKLMNOPQRSTUVWXYZ "); $ ResultStr = C: Random ($ randArray, $ param ); If ($ capslock ){ Return strtoupper ($ resultStr ); } Else { Return $ resultStr; } } // Encrypted string Static public function EnBaseCode ($ data, $ key = "ZCStrong "){ $ Key = md5 ($ key); // For the preset KEY, MD5 $ X = 0; $ Len = strlen ($ data ); $ L = strlen ($ key ); For ($ I = 0; $ I <$ len; $ I ++ ){ If ($ x = $ l ){ $ X = 0; } $ Char. = $ key {$ x }; $ X ++; } For ($ I = 0; $ I <$ len; $ I ++ ){ $ Str. = chr (ord ($ data {$ I}) + (ord ($ char {$ I}) % 256 ); } Return base64_encode ($ str ); } // Secret string Static public function DeBaseCode ($ data, $ key = "ZCStrong "){ $ Key = md5 ($ key ); $ X = 0; $ Data = base64_decode ($ data ); $ Len = strlen ($ data ); $ L = strlen ($ key ); For ($ I = 0; $ I <$ len; $ I ++ ){ If ($ x = $ l ){ $ X = 0; } $ Char. = substr ($ key, $ x, 1 ); $ X ++; } For ($ I = 0; $ I <$ len; $ I ++ ){ If (ord (substr ($ data, $ I, 1) <ord (substr ($ char, $ I, 1 ))){ $ Str. = chr (ord (substr ($ data, $ I, 1) + 256)-ord (substr ($ char, $ I, 1 ))); } Else { $ Str. = chr (ord (substr ($ data, $ I, 1)-ord (substr ($ char, $ I, 1 ))); } } Return $ str; } // Regular phone number/^ (1 [, 8] [0-9]) | (14 []) | (17 [,]) \ d {8} $/ Static public function RegularPhone ($ string ){ $ ResultStr = preg_match ("/^ (1 [, 8] [0-9]) | (14 []) | (17 [,]) \ d {8 }$/", $ string ); If (intval ($ resultStr) = 1 ){ Return TRUE; } Else { Return FALSE; } } // Regular email Static public function RegularEmail ($ string ){ $ ResultStr = preg_match ("/^ ([0-9A-Za-z \-_ \.] +) @ ([0-9a-z] + \\. [a-z] {2, 3 }(\\. [a-z] {2 })?) $/I ", $ string ); If (intval ($ resultStr) = 1 ){ Return TRUE; } Else { Return FALSE; } } // Regular Expression verification ID card/(^ ([d] {15} | [d] {18} | [d] {17} x) $ )/ Static public function RegularIdCard ($ string ){ $ ResultStr = preg_match ("/(^ ([d] {15} | [d] {18} | [d] {17} x) $ )/", $ string ); If (intval ($ resultStr) = 1 ){ Return TRUE; } Else { Return FALSE; } } // Process string Information Static public function hStr ($ string ){ If (isset ($ string )&&! Empty ($ string )){ Return addslashes (strip_tags ($ string )); } Else { Return ""; } } } |