What are the considerations for handling character encoding and locale settings when formatting dates in PHP?

When formatting dates in PHP, it is important to consider character encoding and locale settings to ensure that the date is displayed correctly for the intended audience. To handle character encoding, make sure that the PHP file itself is saved with the appropriate encoding (such as UTF-8) and use functions like utf8_encode() or utf8_decode() when necessary. For locale settings, use setlocale() to specify the desired locale for date formatting.

<?php
// Set the character encoding
header('Content-Type: text/html; charset=utf-8');

// Set the locale for date formatting
setlocale(LC_TIME, 'en_US.UTF-8');

// Format the date
$date = strtotime('2022-01-01');
$formatted_date = strftime('%A, %B %d, %Y', $date);

echo $formatted_date;
?>