Good evening, there is a problem with regex and file encoding There is a php script
<? # Если не передан параметр if (!defined('UF_AUTOLOADER_SETUP')) die(header('Location: /404/')); # Переменные $message = urldecode($project['text']); # Проверка if(!preg_match('/^[^\.][0-9a-zA-Zа-яёА-ЯЁА\s\-\.\,\_\!\?\(\)]+[^\.]/', $message)) die(json_encode(Array('type' => 'error', 'errid' => '024'))); # Проверка if(empty($project['id']) || empty($message) || empty($project['captcha'])) die(json_encode(Array('type' => 'error', 'errid' => '004', 'critical' => true))); # Проверка на пустоту. $message = trim($message); if(!empty($message)){ # Замена [br/] $test = str_replace('[br/]', '', $message); $message = str_replace('[br/]', '%BR%', $message); # Проверка if($test == '') die(json_encode(Array('type' => 'error', 'errid' => '024'))); # Парсим пустые BB коды $confing = new confing(); if($confing->parser($message, 'check') == 0){ # Проверки на пустоту. if($confing->parser($message, 'remove') == '') die(json_encode(Array('type' => 'error', 'errid' => '024'))); # Пустые BB Коды } else die(json_encode(Array('type' => 'error', 'errid' => '024'))); # Замена %BR% $message = str_replace('%BR%', '[br/]', $message); # Добавляем комментарий $add = $db->insert("INSERT INTO `umbrella_forum_messages` (`uid`, `tid`, `fid`, `message`, `time`, `tm`) VALUES (?, ?, ?, ?, ?, ?)", Array($_SESSION['id'], $project['id'], $topic['fid'], htmlspecialchars($message), date("Ymd H:i:s"), 't')); # Ответ die(json_encode(Array('request' => 'forum', 'type' => 'newmessage', 'status' => true, 'mid' => intval($add), 'id' => intval($project['id']), 'overpage' => $page))); } else die(json_encode(Array('type' => 'error', 'errid' => '024')));
The message itself is transmitted via js (json format), the encoding in the JS file is UTF-8, the php file encoding is windows-1251, when sending a message, it gives me an error
if(!preg_match('/^[^\.][0-9a-zA-Zа-яёА-ЯЁА\s\-\.\,\_\!\?\(\)]+[^\.]/', $message)) die(json_encode(Array('type' => 'error', 'errid' => '024')));
Tried to escape the encoding:
$message = iconv("UTF-8", "windows-1251", urldecode($project['text']));
As a result, all Russian characters simply disappeared and an empty message went into the database ... What exactly am I doing wrong or what is the php code error?
if(!preg_match('/^[^\.][0-9a-zA-Zа-яёА-ЯЁА\s\-\.\,\_\!\?\(\)]+[^\.]/', $message))
? - Visman