wpcf7_canonicalize()
Canonicalizes text.
Хуков нет.
Возвращает
Строку. Canonicalized text.
Использование
wpcf7_canonicalize( $text, $options );
- $text(строка) (обязательный)
- Input text.
- $options(строка|массив|объект)
- Options.
По умолчанию:''
Код wpcf7_canonicalize() wpcf7 canonicalize CF7 6.1.6
function wpcf7_canonicalize( $text, $options = '' ) {
// for back-compat
if (
is_string( $options ) and
'' !== $options and
! str_contains( $options, '=' )
) {
$options = array(
'strto' => $options,
);
}
$options = wp_parse_args( $options, array(
'strto' => 'lower',
'strip_separators' => false,
) );
static $charset = null;
if ( ! isset( $charset ) ) {
$charset = get_option( 'blog_charset' );
$is_utf8 = in_array(
$charset,
array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ),
true
);
if ( $is_utf8 ) {
$charset = 'UTF-8';
}
}
$text = html_entity_decode( $text, ENT_QUOTES | ENT_HTML5, $charset );
if ( function_exists( 'mb_convert_kana' ) ) {
$text = mb_convert_kana( $text, 'asKV', $charset );
}
if ( $options['strip_separators'] ) {
$text = preg_replace( '/[\r\n\t ]+/', '', $text );
} else {
$text = preg_replace( '/[\r\n\t ]+/', ' ', $text );
}
if ( 'lower' === $options['strto'] ) {
if ( function_exists( 'mb_strtolower' ) ) {
$text = mb_strtolower( $text, $charset );
} else {
$text = strtolower( $text );
}
} elseif ( 'upper' === $options['strto'] ) {
if ( function_exists( 'mb_strtoupper' ) ) {
$text = mb_strtoupper( $text, $charset );
} else {
$text = strtoupper( $text );
}
}
return wpcf7_strip_whitespaces( $text );
}