UTF-8 with php pdo 和 mysql - ctype php

UTF-8 with php pdo and mysql - ctype php

如何使用 ctype_alpha 和 UTF-8

我有这个代码:

 if(empty($_POST) === false) {      

                if (isset($_POST['first_name']) && !empty ($_POST['first_name'])){
                    if (ctype_alpha($_POST['first_name']) === false) {
                    $errors[] = 'Please enter your First Name with only letters!';
                    }   
                }

所以在这里我检查一切正常,如果不是我得到错误...

但是如果我使用像 ščćž - UTF-8 这样的字母,那么我也会得到错误,所以我该如何解决这个问题,因为我需要名字有 onlz 个字母,但我需要允许像 ščćž 这样的 UTF-8 字符

请帮忙!

确保一切都是 UTF8 NOBOM 格式。所有 php 个文件必须以 UTF8 NOBOM 格式保存。仅将 "charset=UTF-8" 添加到 html 标签是不够的。

此外,您还必须为数据库连接设置 UTF8:

mysql_query ('SET NAMES utf8');

Please look at the below line

 if (ctype_alpha($_POST['last_name']) === false) {
                    $errors[] = 'Please use only alfabetic charecters';
                    } 



if you see condition of the ctype_alpha it is telling that if it is not contain an alphabet then throw an error, you need to remove that condition.


I hope this helps you.