函数原型
prep_atom_text_construct( string $data ): array
函数描述
Determines the type of a string of data with the data formatted.
是否弃用
未弃用
函数参数
-
$data
string
Required - Input string.
函数返回值
array array(type, value)
函数位置
File: wp-includes/feed.php.
函数源码
function prep_atom_text_construct( $data ) {
if ( strpos( $data, '<' ) === false && strpos( $data, '&' ) === false ) {
return array( 'text', $data );
}
if ( ! function_exists( 'xml_parser_create' ) ) {
trigger_error( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) );
return array( 'html', "<![CDATA[$data]]>" );
}
$parser = xml_parser_create();
xml_parse( $parser, '<div>' . $data . '</div>', true );
$code = xml_get_error_code( $parser );
xml_parser_free( $parser );
unset( $parser );
if ( ! $code ) {
if ( strpos( $data, '<' ) === false ) {
return array( 'text', $data );
} else {
$data = "<div xmlns='http://www.w3.org/1999/xhtml'>$data</div>";
return array( 'xhtml', $data );
}
}
if ( strpos( $data, ']]>' ) === false ) {
return array( 'html', "<![CDATA[$data]]>" );
} else {
return array( 'html', htmlspecialchars( $data ) );
}
}
源码链接
变更日志
| Version | Description |
|---|---|
| 2.5.0 | Introduced. |

