PHP verification form Implementation Method

Source: Internet
Author: User

LearningThe PHP verification form code is as follows:

 
  1. <?Php
  2. Class class_post
  3. {
  4. // Verify whether it is a combination of letters and numbers with a specified length
  5. Function fun_text1 ($ num1, $ num2, $ str)
  6. {
  7. Return (preg_match ("/^ [a-zA-Z0-9] {". $ num1. ",". $ num2. "} $/", $ str ))? True: false;
  8. }
  9. // Verify whether it is a number of the specified length
  10. Function fun_text2 ($ num1, $ num2, $ str)
  11. {
  12. Return (preg_match ("/^ [0-9] {". $ num1. ",". $ num2. "} $/I", $ str ))? True: false;
  13. }
  14. // Verify whether the Chinese character is of the specified length
  15. Function fun_font ($ num1, $ num2, $ str)
  16. {
  17. // Preg_match ("/^ [xa0-xff] {} $/", $ string );
  18. Return (preg_match ("/^ ([x81-xfe] [x40-xfe]) {". $ num1. ",". $ num2. "} $/", $ str ))? True: false;
  19. }
  20. // Verify the ID card number
  21. Function fun_status ($ str)
  22. {
  23. Return (preg_match ('/(^ ([d] {15} | [d] {18} | [d] {17} x) $ )/', $ str ))? True: false;
  24. }
  25.  
  26. // Verify the email address
  27. Function fun_email ($ str ){
  28. Return (preg_match ('/^ [_. 0-9a-z-] + @ ([0-9a-z] [0-9a-z-] + .) + [a-z] {2, 4} $/', $ str ))? True: false;
  29. }
  30. // Verify the phone number
  31. Function fun_phone ($ str)
  32. {
  33.  
  34. Return (preg_match ("/^ (d {3}) | (d {3 }-))? (0d {2, 3}) | 0d {2, 3 }-)? [1-9] d {6, 7} $/", $ str ))? True: false;
  35. }
  36. // Verify the zip code
  37. Function fun_zip ($ str)
  38. {
  39. Return (preg_match ("/^ [1-9] d {5} $/", $ str ))? True: false;
  40. }
  41. // Verify the url
  42. Function fun_url ($ str)
  43. {
  44. Return (preg_match ("/^ http: // [A-Za-z0-9] +. [A-Za-z0-9] + [/=? % -&_~ '@ []': +!] * ([^<>""]) * $/", $ Str ))? True: false;
  45. }
  46.  
  47. // The data warehouse receiving escape special character input value can be a string or a one-dimensional array
  48. Function data_join (& $ data)
  49. {
  50. If (get_magic_quotes_gpc () = false)
  51. {
  52. If (is_array ($ data ))
  53. {
  54. Foreach ($ data as $K=>$ V)
  55. {
  56. $ Data [$ k] = addslashes ($ v );
  57. }
  58. }
  59. Else
  60. {
  61. $Data=Addslashes($ Data );
  62. }
  63. }
  64. Return $ data; return (preg_match ("/^ (d {3}) | (d {3 }-))? (0d {2, 3}) | 0d {2, 3 }-)? [1-9] d {6, 7} $/", $ str ))? True: false;
  65. }
  66.  
  67. // Data warehouse restore special character input value can be a string or one/two-dimensional array
  68. Function data_revert (& $ data)
  69. {
  70. If (is_array ($ data ))
  71. {
  72. Foreach ($ data as $K1=>$ V1)
  73. {
  74. If (is_array ($ v1 ))
  75. {
  76. Foreach ($ v1 as $K2=>$ V2)
  77. {
  78. $ Data [$ k1] [$ k2] = stripslashes ($ v2 );
  79. }
  80. }
  81. Else
  82. {
  83. $ Data [$ k1] = stripslashes ($ v1 );
  84. }
  85. }
  86. }
  87. Else
  88. {
  89. $Data=Stripslashes($ Data );
  90. }
  91. Return $ data;
  92. }
  93.  
  94. // The data display restoration data format is mainly used for the input value of the content output to be a string or A/two-dimensional array.
  95. // Data_revert () should be performed before this method is executed, and the form content does not need to be restored
  96. Function data_show (& $ data)
  97. {
  98.  
  99. If (is_array ($ data ))
  100. {
  101. Foreach ($ data as $K1=>$ V1)
  102. {
  103. If (is_array ($ v1 ))
  104. {
  105. Foreach ($ v1 as $K2=>$ V2)
  106. {
  107. $ Data [$ k1] [$ k2] = nl2br (htmlspecialchars ($ data [$ k1] [$ k2]);
  108. $ Data [$ k1] [$ k2] = str_replace ("", "", $ data [$ k1] [$ k2]);
  109. $ Data [$ k1] [$ k2] = str_replace ("","<Br>", $ Data [$ k1] [$ k2]);
  110. }
  111. }
  112. Else
  113. {
  114. $ Data [$ k1] = nl2br (htmlspecialchars ($ data [$ k1]);
  115. $ Data [$ k1] = str_replace ("", "", $ data [$ k1]);
  116. $ Data [$ k1] = str_replace ("","<Br>", $ Data [$ k1]);
  117. }
  118. }
  119. }
  120. Else
  121. {
  122. $Data=Nl2br(Htmlspecialchars ($ data ));
  123. $Data=Str_replace("", "", $ Data );
  124. $Data=Str_replace("","<Br>", $ Data );
  125. }
  126. Return $ data;
  127. }
  128. }
  129. If (is_array ($ data ))
  130. {
  131. Foreach ($ data as $K1=>$ V1)
  132. {
  133. If (is_array ($ v1 ))
  134. {
  135. Foreach ($ v1 as $K2=>$ V2)
  136. {
  137. $ Data [$ k1] [$ k2] = nl2br (htmlspecialchars ($ data [$ k1] [$ k2]);
  138. $ Data [$ k1] [$ k2] = str_replace ("", "", $ data [$ k1] [$ k2]);
  139. $ Data [$ k1] [$ k2] = str_replace ("","<Br>", $ Data [$ k1] [$ k2]);
  140. }
  141. }
  142. Else
  143. {
  144. $ Data [$ k1] = nl2br (htmlspecialchars ($ data [$ k1]);
  145. $ Data [$ k1] = str_replace ("", "", $ data [$ k1]);
  146. $ Data [$ k1] = str_replace ("","<Br>", $ Data [$ k1]);
  147. }
  148. }
  149. }
  150. Else
  151. {
  152. $Data=Nl2br(Htmlspecialchars ($ data ));
  153. $Data=Str_replace("", "", $ Data );
  154. $Data=Str_replace("","<Br>", $ Data );
  155. }
  156. Return $ data;
  157. }
  158. }
  159. ?> 

The above code is related to the PHP verification form implementation method.


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.