htmlentities2( string $text ): string

In this article

Converts entities, while preserving already-encoded entities.

Parameters

$textstringrequired
The text to be converted.

Return

string Converted text.

Source

function htmlentities2( $text ) {
	$translation_table = get_html_translation_table( HTML_ENTITIES, ENT_QUOTES );

	$translation_table[ chr( 38 ) ] = '&';

	return preg_replace( '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/', '&', strtr( $text, $translation_table ) );
}

Changelog

VersionDescription
1.2.2Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.