In what situations should headers be used to specify character encoding in PHP scripts?

Headers should be used to specify character encoding in PHP scripts when you want to ensure that the browser interprets the content correctly. This is especially important when dealing with special characters or non-ASCII characters. By setting the correct character encoding in the headers, you can avoid issues such as garbled text or incorrect display of characters in the browser.

header('Content-Type: text/html; charset=utf-8');