PHP Common handling static action class

Source: Internet
Author: User
Tags chr md5 ord strlen

Detailed a PHP development often with the handling of the operation of the class-I hope you have a lot to add-perfect this operation class

 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26-27--28 29---30 31--32 33 34 35 36 37 38-39 40 41 42 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 5, 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 11 9 120 121 122 123 124 125 126 127 128 129 <?php/** * Commonly used static classes, where the main collation of some PHP will often use the method. * * @author Zcstrong-youkuiyuan/class C {* * * private processing random number of built-in parameters * Array random number/param random number length * Returns a random number/static private fun Ction 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 (numeric type) static public function randnum ($param = 8) {$randArray = Str_split ("1234567890"); $resultStr = C::ran Dom ($randArray, $param); return $resultStr;  //random number (mixed type)-no 0 static public function randstr ($param = 8, $capslock = FALSE) {$randArray = Str_split ("abcdefgh Ijklmnopqrstuvwxyz123456789abcdefghigklmnopqrstuvwxyz "); $RESULTSTR = C::random ($randArray, $param); if ($capslock) {return strtoupper ($RESULTSTR);} else {return $resultStr;}}  //Encrypt string static public function Enbasecode ($data, $key = "Zcstrong") {$key = MD5 ($key);//For 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 + +) {$s tr. = Chr (Ord ($data {$i}) + (Ord ($char {$i}))% 256); Return Base64_encode ($STR); }  //confidential string static public function Debasecode ($data, $key = "Zcstrong") {$key = MD5 ($key); $x = 0; $data = Base64_dec Ode ($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 substr ($char, $i, 1)); else{$str. = Chr (Ord (substr ($data, $i, 1))-Ord (substr ($char, $i, 1));} return $str;  //Regular mobile phone number/^ ((1[3,5,8][0-9]) | ( 14[5,7]) | (17[0,6,7,8]) d{8}$/static public Function Regularphone ($string) {$resultStr = Preg_match ("/^" ((1[3,5,8][0-9)) | ( 14[5,7]) | (17[0,6,7,8]) d{8}$/", $string); if (intval ($resultStr) = = 1) {RETurn TRUE; } else{return FALSE;}  //Regular mailbox 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 verification ID/(^ ([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;}}  //handling string information static public function Hstr ($string) {if (Isset ($string) &&!empty ($string)) {return addslashes ( Strip_tags ($string)); } else{return "";}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.