What is the best way to automatically generate an alias from a data entry title in PHP?

When generating an alias from a data entry title in PHP, one approach is to remove any special characters, spaces, and convert the title to lowercase. This can be achieved using PHP functions like strtolower(), preg_replace(), and str_replace(). Additionally, you can replace spaces with a specified character like hyphens or underscores for a cleaner alias.

// Sample data entry title
$title = "This is a Sample Title!";

// Generate alias from the title
$alias = strtolower(str_replace(' ', '-', preg_replace('/[^A-Za-z0-9 ]/', '', $title)));

echo $alias; // Output: this-is-a-sample-title