Use the following code in your script to set the internal php encoding to UTF-8:
/* Set internal character encoding to UTF-8 */
mb_internal_encoding("UTF-8");
mb_http_output( "UTF-8" );
ob_start("mb_output_handler");
Code language: JavaScript (javascript)
Also, for mysql and postgres you should take into consideration the following two commands:
SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'
Code language: JavaScript (javascript)
update pg_database set encoding = pg_char_to_encoding('UTF8') where datname = 'thedb'
Code language: PHP (php)