In the context of PHP, what are some best practices for generating SEO-friendly URLs from user input such as page titles?

When generating SEO-friendly URLs from user input such as page titles, it is important to sanitize and format the input to remove any special characters, spaces, and make it lowercase. This can be achieved by using functions like `strtolower()`, `preg_replace()`, and `urlencode()` in PHP. Additionally, you can replace spaces with dashes to create a clean and readable URL structure.

// Example code to generate SEO-friendly URL from user input
$userInput = "This is a Page Title";

// Sanitize the input
$urlFriendly = strtolower($userInput); // Convert to lowercase
$urlFriendly = preg_replace('/[^a-z0-9]+/', '-', $urlFriendly); // Remove special characters
$urlFriendly = urlencode($urlFriendly); // Encode the URL

echo $urlFriendly; // Output: this-is-a-page-title