How can you ensure proper encoding and display of special characters like umlauts in PHP when querying a database?

Special characters like umlauts can be properly encoded and displayed in PHP by setting the correct character encoding for both the database connection and the output. This can be achieved by using functions like mysqli_set_charset() to set the character encoding for the database connection, and header() function with Content-Type meta tag to set the character encoding for the output.

// Set character encoding for database connection
mysqli_set_charset($connection, 'utf8');

// Set character encoding for output
header('Content-Type: text/html; charset=utf-8');