convert_invalid_entities() WordPress Function

The convert_invalid_entities() function is used to convert invalid HTML entities into valid ones. This is useful when you want to display content that may contain invalid HTML entities, such as when you're displaying user-generated content.

convert_invalid_entities( string $content ) #

Converts invalid Unicode references range to valid range.


Parameters

$content

(string)(Required)String with entities that need converting.


Top ↑

Return

(string) Converted string.


Top ↑

Source

File: wp-includes/formatting.php

function convert_invalid_entities( $content ) {
	$wp_htmltranswinuni = array(
		'€' => '€', // The Euro sign.
		'' => '',
		'‚' => '‚', // These are Windows CP1252 specific characters.
		'ƒ' => 'ƒ',  // They would look weird on non-Windows browsers.
		'„' => '„',
		'…' => '…',
		'†' => '†',
		'‡' => '‡',
		'ˆ' => 'ˆ',
		'‰' => '‰',
		'Š' => 'Š',
		'‹' => '‹',
		'Œ' => 'Œ',
		'' => '',
		'Ž' => 'Ž',
		'' => '',
		'' => '',
		'‘' => '‘',
		'’' => '’',
		'“' => '“',
		'”' => '”',
		'•' => '•',
		'–' => '–',
		'—' => '—',
		'˜' => '˜',
		'™' => '™',
		'š' => 'š',
		'›' => '›',
		'œ' => 'œ',
		'' => '',
		'ž' => 'ž',
		'Ÿ' => 'Ÿ',
	);

	if ( strpos( $content, '&#1' ) !== false ) {
		$content = strtr( $content, $wp_htmltranswinuni );
	}

	return $content;
}

Top ↑

Changelog

Changelog
VersionDescription
4.3.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More