Hello Friends Today, through this tutorial, I will tell you How do you decode HTML entities in a string using the in PHP With Example? In PHP, you can decode HTML entities in a string using the `html_entity_decode()` function. This function converts HTML entities to their corresponding characters. Here's an example:
<?php
// Example string containing HTML entities
$string = "This is <b>bold</b> and "quoted" text.";
// Decode HTML entities
$decoded_string = html_entity_decode($string);
// Output decoded string
echo "Original string: $string <br>";
echo "Decoded string: $decoded_string";
?>
In this example:
1. We have a string `$string` that contains HTML entities such as `<`, `>`, and `"`.
2. We use the `html_entity_decode()` function to decode these HTML entities.
3. The decoded string is stored in the variable `$decoded_string`.
4. We then output both the original and decoded strings using `echo`.
Output:
Original string: This is <b>bold</b> and "quoted" text.
Decoded string: This is <b>bold</b> and "quoted" text.
As you can see, the HTML entities in the original string have been decoded to their corresponding characters in the decoded string.