What potential pitfalls should be avoided when using {modal} tags in PHP scripts for Joomla modules?

When using {modal} tags in PHP scripts for Joomla modules, it's important to avoid directly echoing the modal content as it can lead to security vulnerabilities such as cross-site scripting (XSS) attacks. Instead, the modal content should be properly sanitized and escaped before being displayed to the user.

// Incorrect way of using {modal} tags
echo '{modal}This is modal content{/modal}';

// Correct way of using {modal} tags
$modalContent = '<p>This is modal content</p>';
echo htmlspecialchars('{modal}' . $modalContent . '{/modal}', ENT_QUOTES, 'UTF-8');