Using WordPress ‘prep_atom_text_construct()’ PHP function

The prep_atom_text_construct WordPress PHP function determines the type of a given string of data, with the data formatted as text, HTML, or XHTML, according to RFC 4287 section 3.1.

Usage

prep_atom_text_construct( $data );

Example:
Input: 'Hello, <strong>World</strong>!'
Output: '<div xmlns="http://www.w3.org/1999/xhtml">Hello, <strong>World</strong></div>'

Parameters

  • $data (string) - Required input string to determine the type.

More information

See WordPress Developer Resources: prep_atom_text_construct

Examples

Plain Text

Description: Determine the type of a plain text string.

$text = 'Hello, World!';
$result = prep_atom_text_construct( $text );
echo $result; // Output: 'Hello, World!'

HTML

Description: Determine the type of an HTML string.

$html = '<p>Hello, <strong>World</strong>!</p>';
$result = prep_atom_text_construct( $html );
echo $result; // Output: '<div xmlns="http://www.w3.org/1999/xhtml"><p>Hello, <strong>World</strong>!</p></div>'

XHTML

Description: Determine the type of an XHTML string.

$xhtml = '<p xmlns="http://www.w3.org/1999/xhtml">Hello, <strong>World</strong>!</p>';
$result = prep_atom_text_construct( $xhtml );
echo $result; // Output: '<div xmlns="http://www.w3.org/1999/xhtml"><p xmlns="http://www.w3.org/1999/xhtml">Hello, <strong>World</strong>!</p></div>'

Mixed Content

Description: Determine the type of a string with mixed content (text and HTML).

$mixed = 'Hello, <strong>World</strong>!';
$result = prep_atom_text_construct( $mixed );
echo $result; // Output: '<div xmlns="http://www.w3.org/1999/xhtml">Hello, <strong>World</strong></div>'

Empty String

Description: Determine the type of an empty string.

$empty = '';
$result = prep_atom_text_construct( $empty );
echo $result; // Output: ''