ent2ncr() WordPress Function

The ent2ncr() function is a WordPress function that converts all HTML entities to their NCR equivalents. NCR is the Windows-1252 encoded version of the ISO-8859-1 character set. This function is useful for writing code that is compatible with both Windows and Linux.

ent2ncr( string $text ) #

Converts named entities into numbered entities.


Parameters

$text

(string)(Required)The text within which entities will be converted.


Top ↑

Return

(string) Text with converted entities.


Top ↑

Source

File: wp-includes/formatting.php

function ent2ncr( $text ) {

	/**
	 * Filters text before named entities are converted into numbered entities.
	 *
	 * A non-null string must be returned for the filter to be evaluated.
	 *
	 * @since 3.3.0
	 *
	 * @param string|null $converted_text The text to be converted. Default null.
	 * @param string      $text           The text prior to entity conversion.
	 */
	$filtered = apply_filters( 'pre_ent2ncr', null, $text );
	if ( null !== $filtered ) {
		return $filtered;
	}

	$to_ncr = array(
		'"'     => '"',
		'&'      => '&',
		'<'       => '<',
		'>'       => '>',
		'|'          => '|',
		' '     => ' ',
		'¡'    => '¡',
		'¢'     => '¢',
		'£'    => '£',
		'¤'   => '¤',
		'¥'      => '¥',
		'¦'   => '¦',
		'&brkbar;'   => '¦',
		'§'     => '§',
		'¨'      => '¨',
		'¨'      => '¨',
		'©'     => '©',
		'ª'     => 'ª',
		'«'    => '«',
		'¬'      => '¬',
		'­'      => '­',
		'®'      => '®',
		'¯'     => '¯',
		'&hibar;'    => '¯',
		'°'      => '°',
		'±'   => '±',
		'²'     => '²',
		'³'     => '³',
		'´'    => '´',
		'µ'    => 'µ',
		'¶'     => '¶',
		'·'   => '·',
		'¸'    => '¸',
		'¹'     => '¹',
		'º'     => 'º',
		'»'    => '»',
		'¼'   => '¼',
		'½'   => '½',
		'¾'   => '¾',
		'¿'   => '¿',
		'À'   => 'À',
		'Á'   => 'Á',
		'Â'    => 'Â',
		'Ã'   => 'Ã',
		'Ä'     => 'Ä',
		'Å'    => 'Å',
		'Æ'    => 'Æ',
		'Ç'   => 'Ç',
		'È'   => 'È',
		'É'   => 'É',
		'Ê'    => 'Ê',
		'Ë'     => 'Ë',
		'Ì'   => 'Ì',
		'Í'   => 'Í',
		'Î'    => 'Î',
		'Ï'     => 'Ï',
		'Ð'      => 'Ð',
		'Ñ'   => 'Ñ',
		'Ò'   => 'Ò',
		'Ó'   => 'Ó',
		'Ô'    => 'Ô',
		'Õ'   => 'Õ',
		'Ö'     => 'Ö',
		'×'    => '×',
		'Ø'   => 'Ø',
		'Ù'   => 'Ù',
		'Ú'   => 'Ú',
		'Û'    => 'Û',
		'Ü'     => 'Ü',
		'Ý'   => 'Ý',
		'Þ'    => 'Þ',
		'ß'    => 'ß',
		'à'   => 'à',
		'á'   => 'á',
		'â'    => 'â',
		'ã'   => 'ã',
		'ä'     => 'ä',
		'å'    => 'å',
		'æ'    => 'æ',
		'ç'   => 'ç',
		'è'   => 'è',
		'é'   => 'é',
		'ê'    => 'ê',
		'ë'     => 'ë',
		'ì'   => 'ì',
		'í'   => 'í',
		'î'    => 'î',
		'ï'     => 'ï',
		'ð'      => 'ð',
		'ñ'   => 'ñ',
		'ò'   => 'ò',
		'ó'   => 'ó',
		'ô'    => 'ô',
		'õ'   => 'õ',
		'ö'     => 'ö',
		'÷'   => '÷',
		'ø'   => 'ø',
		'ù'   => 'ù',
		'ú'   => 'ú',
		'û'    => 'û',
		'ü'     => 'ü',
		'ý'   => 'ý',
		'þ'    => 'þ',
		'ÿ'     => 'ÿ',
		'Œ'    => 'Œ',
		'œ'    => 'œ',
		'Š'   => 'Š',
		'š'   => 'š',
		'Ÿ'     => 'Ÿ',
		'ƒ'     => 'ƒ',
		'ˆ'     => 'ˆ',
		'˜'    => '˜',
		'Α'    => 'Α',
		'Β'     => 'Β',
		'Γ'    => 'Γ',
		'Δ'    => 'Δ',
		'Ε'  => 'Ε',
		'Ζ'     => 'Ζ',
		'Η'      => 'Η',
		'Θ'    => 'Θ',
		'Ι'     => 'Ι',
		'Κ'    => 'Κ',
		'Λ'   => 'Λ',
		'Μ'       => 'Μ',
		'Ν'       => 'Ν',
		'Ξ'       => 'Ξ',
		'Ο'  => 'Ο',
		'Π'       => 'Π',
		'Ρ'      => 'Ρ',
		'Σ'    => 'Σ',
		'Τ'      => 'Τ',
		'Υ'  => 'Υ',
		'Φ'      => 'Φ',
		'Χ'      => 'Χ',
		'Ψ'      => 'Ψ',
		'Ω'    => 'Ω',
		'α'    => 'α',
		'β'     => 'β',
		'γ'    => 'γ',
		'δ'    => 'δ',
		'ε'  => 'ε',
		'ζ'     => 'ζ',
		'η'      => 'η',
		'θ'    => 'θ',
		'ι'     => 'ι',
		'κ'    => 'κ',
		'λ'   => 'λ',
		'μ'       => 'μ',
		'ν'       => 'ν',
		'ξ'       => 'ξ',
		'ο'  => 'ο',
		'π'       => 'π',
		'ρ'      => 'ρ',
		'ς'   => 'ς',
		'σ'    => 'σ',
		'τ'      => 'τ',
		'υ'  => 'υ',
		'φ'      => 'φ',
		'χ'      => 'χ',
		'ψ'      => 'ψ',
		'ω'    => 'ω',
		'ϑ' => 'ϑ',
		'ϒ'    => 'ϒ',
		'ϖ'      => 'ϖ',
		' '     => ' ',
		' '     => ' ',
		' '   => ' ',
		'‌'     => '‌',
		'‍'      => '‍',
		'‎'      => '‎',
		'‏'      => '‏',
		'–'    => '–',
		'—'    => '—',
		'‘'    => '‘',
		'’'    => '’',
		'‚'    => '‚',
		'“'    => '“',
		'”'    => '”',
		'„'    => '„',
		'†'   => '†',
		'‡'   => '‡',
		'•'     => '•',
		'…'   => '…',
		'‰'   => '‰',
		'′'    => '′',
		'″'    => '″',
		'‹'   => '‹',
		'›'   => '›',
		'‾'    => '‾',
		'⁄'    => '⁄',
		'€'     => '€',
		'ℑ'    => 'ℑ',
		'℘'   => '℘',
		'ℜ'     => 'ℜ',
		'™'    => '™',
		'ℵ'  => 'ℵ',
		'↵'    => '↵',
		'⇐'     => '⇐',
		'⇑'     => '⇑',
		'⇒'     => '⇒',
		'⇓'     => '⇓',
		'⇔'     => '⇔',
		'∀'   => '∀',
		'∂'     => '∂',
		'∃'    => '∃',
		'∅'    => '∅',
		'∇'    => '∇',
		'∈'     => '∈',
		'∉'    => '∉',
		'∋'       => '∋',
		'∏'     => '∏',
		'∑'      => '∑',
		'−'    => '−',
		'∗'   => '∗',
		'√'    => '√',
		'∝'     => '∝',
		'∞'    => '∞',
		'∠'      => '∠',
		'∧'      => '∧',
		'∨'       => '∨',
		'∩'      => '∩',
		'∪'      => '∪',
		'∫'      => '∫',
		'∴'   => '∴',
		'∼'      => '∼',
		'≅'     => '≅',
		'≈'    => '≈',
		'≠'       => '≠',
		'≡'    => '≡',
		'≤'       => '≤',
		'≥'       => '≥',
		'⊂'      => '⊂',
		'⊃'      => '⊃',
		'⊄'     => '⊄',
		'⊆'     => '⊆',
		'⊇'     => '⊇',
		'⊕'    => '⊕',
		'⊗'   => '⊗',
		'⊥'     => '⊥',
		'⋅'     => '⋅',
		'⌈'    => '⌈',
		'⌉'    => '⌉',
		'⌊'   => '⌊',
		'⌋'   => '⌋',
		'⟨'     => '〈',
		'⟩'     => '〉',
		'←'     => '←',
		'↑'     => '↑',
		'→'     => '→',
		'↓'     => '↓',
		'↔'     => '↔',
		'◊'      => '◊',
		'♠'   => '♠',
		'♣'    => '♣',
		'♥'   => '♥',
		'♦'    => '♦',
	);

	return str_replace( array_keys( $to_ncr ), array_values( $to_ncr ), $text );
}


Top ↑

Changelog

Changelog
VersionDescription
1.5.1Introduced.

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