sanitize_email
函数
sanitize_email ( $email )
- 参数
-
-
(string)
$email
Email address to filter.- Required: 是
-
(string)
- 返回值
-
- (string) Filtered email address.
- 定义位置
-
-
wp-includes/formatting.php
, line 3681
-
wp-includes/formatting.php
- 引入
- 1.5.0
- 弃用
- –
Strips out all characters that are not allowable in an email.
function sanitize_email( $email ) { // Test for the minimum length the email can be. if ( strlen( $email ) count( $subs ) ) { /** This filter is documented in wp-includes/formatting.php */ return apply_filters( 'sanitize_email', '', $email, 'domain_no_periods' ); } // Create an array that will contain valid subs. $new_subs = array(); // Loop through each sub. foreach ( $subs as $sub ) { // Test for leading and trailing hyphens. $sub = trim( $sub, " tnrx0B-" ); // Test for invalid characters. $sub = preg_replace( '/[^a-z0-9-]+/i', '', $sub ); // If there's anything left, add it to the valid subs. if ( '' !== $sub ) { $new_subs[] = $sub; } } // If there aren't 2 or more valid subs. if ( 2 > count( $new_subs ) ) { /** This filter is documented in wp-includes/formatting.php */ return apply_filters( 'sanitize_email', '', $email, 'domain_no_valid_subs' ); } // Join valid subs into the new domain. $domain = implode( '.', $new_subs ); // Put the email back together. $sanitized_email = $local . '@' . $domain; // Congratulations, your email made it! /** This filter is documented in wp-includes/formatting.php */ return apply_filters( 'sanitize_email', $sanitized_email, $email, null ); }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。