prep_atom_text_construct

Definition:
function prep_atom_text_construct($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.

Parameters

  • string $data: Input string

Return values

returns:array(type, value)

Source code

function prep_atom_text_construct($data) {

	if (strpos($data, '<') === false && strpos($data, '&') === false) {

		return array('text', $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));

	}

}

2601

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: