prep_atom_text_construct

函式
prep_atom_text_construct ( $data )
引數
  • (string) $data Input string.
    Required:
返回值
  • (array) array(type, value)
定義位置
相關方法
_deprecated_constructorget_attachment_icon_srcatom_site_iconget_the_contentwp_update_term_count
引入
2.5.0
棄用
-

prep_atom_text_construct函式是WordPress的一個函式,用於準備顯示Atom文字結構。它用於格式化Atom feed中的文字內容,通常用於過濾器掛鉤。

確定一串資料的型別,並對資料進行格式化。

根據RFC 4287第3.1節,告訴該型別是文字、HTML還是XHTML。

在WordPress的情況下,文字被定義為不包含標記。
XHTML被定義為””形成良好的””,而HTML是標籤湯(即其餘的)。

根據第3.1.1.3節,容器div標籤被新增到XHTML值中。

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 ) );
	}
}

常見問題

FAQs
檢視更多 >