Support PHP Version: PHP 7.1, PHP 7.2, PHP 7.3, PHP 7.4, PHP 8.0, PHP 8.1, PHP 8.2, PHP 8.3 With Latest All Version Support.
Hello Friends Today, through this tutorial, I will tell you How to Use `html_entity_decode()` function using PHP, PHP 8, PHP 8.1, PHP 8.2 With Example. In PHP, the `html_entity_decode()` function is used to convert HTML entities to their corresponding characters. This function can be particularly useful when you have HTML content with encoded entities that you want to display as plain text.
Here’s how you can use the `html_entity_decode()` function in PHP 8.1 and 8.2 with an example:
<?php // Example HTML content with encoded entities $html_content = "<p>This is an example &lt;p&gt; HTML content.</p>"; // Using html_entity_decode() to decode HTML entities $decoded_content = html_entity_decode($html_content); // Displaying the decoded content echo "Decoded Content: " . $decoded_content; ?>
Output:
Decoded Content: <p>This is an example <p> HTML content.</p>
In this example:
1. We have a string `$html_content` containing HTML content with encoded entities.
2. We use the `html_entity_decode()` function to decode the HTML entities in the content.
3. The decoded content is stored in the variable `$decoded_content`.
4. Finally, we display the decoded content using `echo`.
This function works similarly in both PHP 8.1 and 8.2. It takes an optional second parameter to specify the encoding, but if omitted, it uses the default encoding (UTF-8).