prep_atom_text_construct()

最后更新于:2021-11-27 19:51:39

prep_atom_text_construct( string$data)

Determine the type of a string of data with the data formatted.

参数

$data

(string) (Required) Input string

响应

(array) array(type, value)

源文件

文件: gc-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 ) );
	}
}