How can PHP functions like html_entity_decode and htmlentities be utilized effectively?

When working with HTML content in PHP, it's important to properly encode and decode special characters to prevent security vulnerabilities like cross-site scripting (XSS) attacks. The functions html_entity_decode() and htmlentities() can be used to decode and encode HTML entities respectively.

// Example of using html_entity_decode to decode HTML entities
$html_content = "<p>This is a <strong>sample</strong> paragraph</p>";
$decoded_content = html_entity_decode($html_content);
echo $decoded_content;

// Example of using htmlentities to encode HTML entities
$text = "<script>alert('XSS attack!')</script>";
$encoded_text = htmlentities($text);
echo $encoded_text;