convert_chars() WordPress Function

The convert_chars() function is a built-in WordPress function that is used to convert special characters to HTML entities. This function is especially useful for converting characters that are not allowed in HTML, such as < and >.

convert_chars( string $content, string $deprecated = '' ) #

Converts lone & characters into &#038; (a.k.a. &amp;)


Parameters

$content

(string)(Required)String of characters to be converted.

$deprecated

(string)(Optional)Not used.

Default value: ''


Top ↑

Return

(string) Converted string.


Top ↑

Source

File: wp-includes/formatting.php

function convert_chars( $content, $deprecated = '' ) {
	if ( ! empty( $deprecated ) ) {
		_deprecated_argument( __FUNCTION__, '0.71' );
	}

	if ( strpos( $content, '&' ) !== false ) {
		$content = preg_replace( '/&([^#])(?![a-z1-4]{1,8};)/i', '&#038;$1', $content );
	}

	return $content;
}


Top ↑

Changelog

Changelog
VersionDescription
0.71Introduced.

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