What are the best practices for displaying and linking database categories with multiple words in PHP?

When displaying and linking database categories with multiple words in PHP, it is best practice to use a standardized format that replaces spaces with dashes or underscores for URLs. This ensures that the categories are properly formatted and can be easily linked and accessed. Additionally, when retrieving categories from the database, it is important to sanitize the data to prevent SQL injection attacks.

// Assuming $category is the category retrieved from the database
$category = str_replace(' ', '-', $category);
$category = urlencode($category);

echo "<a href='category.php?name=$category'>$category</a>";