The ent2ncr() WordPress PHP function converts named entities into numbered entities within a given text.
Usage
Here’s an example of how you could use the ent2ncr() function:
$text = "C’est la fête!"; echo ent2ncr($text);
This outputs: C’est la fête!
Parameters
- $text (string) – This is the text within which entities will be converted.
More Information
See WordPress Developer Resources: ent2ncr()
This function is a part of WordPress Core and is included in all versions of WordPress since 2.8.0. It has not been deprecated and is an integral part of the WordPress HTML API.
Examples
Basic Usage
This is a simple usage of ent2ncr() function.
$text = "Léon"; // French name with a named entity echo ent2ncr($text);
This will output: Léon
.
Converting Multiple Entities
In this example, we convert multiple named entities in a sentence.
$text = "J’aime les crêpes"; // I love crepes in French echo ent2ncr($text);
This will output: J’aime les crêpes
.
Using with HTML Tags
Here we’re showing how ent2ncr() works with HTML tags.
$text = "<p>Bonjour, c&rsquo;est moi!</p>"; // Hello, it's me in French echo ent2ncr($text);
This will output: <p>Bonjour, c’est moi!</p>
.
Using with Special Characters
This example demonstrates how ent2ncr() handles special characters.
$text = "M&icirc;nous, l&rsquo;&eacute;l&egrave;ve!"; // Go, the student! in French echo ent2ncr($text);
This will output: Mînous, l’élève!
.
Using with Non-ASCII Characters
This example shows how ent2ncr() function can also handle non-ASCII characters.
$text = "C&rsquo;est la f&ecirc;te!"; // It's a party! in French echo ent2ncr($text);
This will output: C’est la fête!
.