What are the best practices for ensuring that IDs and names for HTML elements in PHP are compliant with HTML standards?

When generating IDs and names for HTML elements in PHP, it is important to ensure they are compliant with HTML standards. To achieve this, it is recommended to use alphanumeric characters, dashes, and underscores only. Avoid using special characters, spaces, or starting with a number. This will help prevent any potential issues with rendering or accessing the elements in the HTML document.

// Generate a compliant ID or name for an HTML element in PHP
$elementName = "my_element";
$elementID = "element_1";