PHP common processing static operations

Source: Internet
Author: User

PHP common processing static operations

A detailed PHP operation class that is often used for development-I hope you can add more-improve 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

43

44

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

84

85

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

119

120

121

122

123

124

125

126

127

128

129

<? 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 "";

}

}

}

Related Article

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.