prep_atom_text_construct() - WordPress 函数参考中文文档

返回介绍

prep_atom_text_construct()

发布于 2017-09-11 字数2182 浏览 927 评论 0

prep_atom_text_construct( string $data )

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


描述

Tell whether the type is text, html, or xhtml, per RFC 4287 section 3.1.

In the case of WordPress, text is defined as containing no markup, xhtml is defined as "well formed", and html as tag soup (i.e., the rest).

Container div tags are added to xhtml values, per section 3.1.1.3.


参数

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

	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 描述
2.5.0 Introduced.

相关函数

Uses

  • wp-includes/l10n.php:
    __()

User Contributed Notes

上一篇:prepend_attachment()

下一篇:press_it()

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!