PHP verification form implementation method-PHP Tutorial

Source: Internet
Author: User
PHP verification form implementation method. The code for learning the PHP verification form is as follows :? Phpclassclass_post {verify whether the functionfun_text1 ($ num1, $ num2, $ str) {Return (preg_match (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. // Verify the email address
  26. Function fun_email ($ str ){
  27. Return (preg_match ('/^ [_. 0-9a-z-] + @ ([0-9a-z] [0-9a-z-] + .) + [a-z] {2, 4} $/', $ str ))? True: false;
  28. }
  29. // Verify the phone number
  30. Function fun_phone ($ str)
  31. {
  32. Return (preg_match ("/^ (d {3}) | (d {3 }-))? (0d {2, 3}) | 0d {2, 3 }-)? [1-9] d {6, 7} $/", $ str ))? True: false;
  33. }
  34. // Verify the ZIP code
  35. Function fun_zip ($ str)
  36. {
  37. Return (preg_match ("/^ [1-9] d {5} $/", $ str ))? True: false;
  38. }
  39. // Verify the url
  40. Function fun_url ($ str)
  41. {
  42. Return (preg_match ("/^ http: // [A-Za-z0-9] +. [A-Za-z0-9] + [/=? % -&_~ '@ []': +!] * ([^<>""]) * $/", $ Str ))? True: false;
  43. }
  44. // The data warehouse receiving escape special character input value can be a string or a one-dimensional array
  45. Function data_join (& $ data)
  46. {
  47. If (get_magic_quotes_gpc () = false)
  48. {
  49. If (is_array ($ data ))
  50. {
  51. Foreach ($ data as $K=>$ V)
  52. {
  53. $ Data [$ k] = addslashes ($ v );
  54. }
  55. }
  56. Else
  57. {
  58. $Data=Addslashes($ Data );
  59. }
  60. }
  61. Return $ data; return (preg_match ("/^ (d {3}) | (d {3 }-))? (0d {2, 3}) | 0d {2, 3 }-)? [1-9] d {6, 7} $/", $ str ))? True: false;
  62. }
  63. // Data warehouse restore special character input value can be a string or one/two-dimensional array
  64. Function data_revert (& $ data)
  65. {
  66. If (is_array ($ data ))
  67. {
  68. Foreach ($ data as $K1=>$ V1)
  69. {
  70. If (is_array ($ v1 ))
  71. {
  72. Foreach ($ v1 as $K2=>$ V2)
  73. {
  74. $ Data [$ k1] [$ k2] = stripslashes ($ v2 );
  75. }
  76. }
  77. Else
  78. {
  79. $ Data [$ k1] = stripslashes ($ v1 );
  80. }
  81. }
  82. }
  83. Else
  84. {
  85. $Data=Stripslashes($ Data );
  86. }
  87. Return $ data;
  88. }
  89. // 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.
  90. // Data_revert () should be performed before this method is executed, and the form content does not need to be restored
  91. Function data_show (& $ data)
  92. {
  93. If (is_array ($ data ))
  94. {
  95. Foreach ($ data as $K1=>$ V1)
  96. {
  97. If (is_array ($ v1 ))
  98. {
  99. Foreach ($ v1 as $K2=>$ V2)
  100. {
  101. $ Data [$ k1] [$ k2] = nl2br (htmlspecialchars ($ data [$ k1] [$ k2]);
  102. $ Data [$ k1] [$ k2] = str_replace ("", "", $ data [$ k1] [$ k2]);
  103. $ Data [$ k1] [$ k2] = str_replace ("","<Br>", $ Data [$ k1] [$ k2]);
  104. }
  105. }
  106. Else
  107. {
  108. $ Data [$ k1] = nl2br (htmlspecialchars ($ data [$ k1]);
  109. $ Data [$ k1] = str_replace ("", "", $ data [$ k1]);
  110. $ Data [$ k1] = str_replace ("","<Br>", $ Data [$ k1]);
  111. }
  112. }
  113. }
  114. Else
  115. {
  116. $Data=Nl2br(Htmlspecialchars ($ data ));
  117. $Data=Str_replace("", "", $ Data );
  118. $Data=Str_replace("","<Br>", $ Data );
  119. }
  120. Return $ data;
  121. }
  122. }
  123. If (is_array ($ data ))
  124. {
  125. Foreach ($ data as $K1=>$ V1)
  126. {
  127. If (is_array ($ v1 ))
  128. {
  129. Foreach ($ v1 as $K2=>$ V2)
  130. {
  131. $ Data [$ k1] [$ k2] = nl2br (htmlspecialchars ($ data [$ k1] [$ k2]);
  132. $ Data [$ k1] [$ k2] = str_replace ("", "", $ data [$ k1] [$ k2]);
  133. $ Data [$ k1] [$ k2] = str_replace ("","<Br>", $ Data [$ k1] [$ k2]);
  134. }
  135. }
  136. Else
  137. {
  138. $ Data [$ k1] = nl2br (htmlspecialchars ($ data [$ k1]);
  139. $ Data [$ k1] = str_replace ("", "", $ data [$ k1]);
  140. $ Data [$ k1] = str_replace ("","<Br>", $ Data [$ k1]);
  141. }
  142. }
  143. }
  144. Else
  145. {
  146. $Data=Nl2br(Htmlspecialchars ($ data ));
  147. $Data=Str_replace("", "", $ Data );
  148. $Data=Str_replace("","<Br>", $ Data );
  149. }
  150. Return $ data;
  151. }
  152. }
  153. ?>

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


The specific code of the signature PHP verification form is as follows :? Php classclass_post {// verify whether the functionfun_text1 ($ num1, $ num2, $ str) {Return (preg_match ("...

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.