prep_atom_text_construct

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

Description

(array) prep_atom_text_construct( (string) $data ); 

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.

Returns (array)

array(type, value)

Parameters (1)

0. $data (string)
Input string

Usage

  1. if ( !function_exists( 'prep_atom_text_construct' ) ) { 
  2. require_once ABSPATH . WPINC . '/feed.php'; 
  3.  
  4. // Input string 
  5. $data = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = prep_atom_text_construct($data); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/feed.php  
  1. function prep_atom_text_construct($data) { 
  2. if (strpos($data, '<') === false && strpos($data, '&') === false) { 
  3. return array('text', $data); 
  4.  
  5. if ( ! function_exists( 'xml_parser_create' ) ) { 
  6. trigger_error( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) ); 
  7.  
  8. return array( 'html', "<![CDATA[$data]]>" ); 
  9.  
  10. $parser = xml_parser_create(); 
  11. xml_parse($parser, '<div>' . $data . '</div>', true); 
  12. $code = xml_get_error_code($parser); 
  13. xml_parser_free($parser); 
  14.  
  15. if (!$code) { 
  16. if (strpos($data, '<') === false) { 
  17. return array('text', $data); 
  18. } else { 
  19. $data = "<div xmlns='http://www.w3.org/1999/xhtml'>$data</div>"; 
  20. return array('xhtml', $data); 
  21.  
  22. if (strpos($data, ']]>') === false) { 
  23. return array('html', "<![CDATA[$data]]>"); 
  24. } else { 
  25. return array('html', htmlspecialchars($data));