What are the potential pitfalls of using incorrect encoding in PHP scripts?

Using incorrect encoding in PHP scripts can lead to issues such as displaying garbled text, incorrect character rendering, and security vulnerabilities like SQL injection attacks. To avoid these pitfalls, it is crucial to ensure that the encoding used in PHP scripts matches the encoding of the data being processed.

// Set the correct encoding for PHP scripts
header('Content-Type: text/html; charset=utf-8');
mb_internal_encoding('UTF-8');