<?php
$str1 = "тест тест тест 11";
$str2 = "test test test 11";
echo mb_detect_encoding($str1)."<br />";
echo mb_detect_encoding($str2)."<br /><br />";
$str1 = iconv('ASCII', 'UTF-8//IGNORE', $str1);
$str2 = iconv('ASCII', 'UTF-8//IGNORE', $str2);
echo mb_detect_encoding($str1)."<br />";
echo mb_detect_encoding($str2)."<br /><br />";
?>
UTF-8
ASCII
ASCII
ASCII
function ConnectToDB($host = 'localhost', $db = 'db', $user = 'root', $pass = ''){
global $pdo;
$charset = 'utf8';
$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
$opt = array(PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE=>PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES=>false);
$pdo = new PDO($dsn, $user, $pass, $opt);
}