Safely Encode Special Characters in an HTML String
Implement a function that converts a raw string into its HTML-safe encoded form by replacing special characters like <, >, &, ", and ' with their corresponding HTML entities (<, >, &, etc.). This is essential for preventing XSS (Cross-Site Scripting) attacks when dynamically injecting user-generated content into the DOM as innerHTML or server-rendered HTML.