English 中文(简体)
mb_strlen()是否足够?
原标题:mb_strlen() is it enough?

在计算PHP I中UTF-8的长度时,使用mb_strlen()

例如:

if (mb_strlen($name,  UTF-8 ) < 3) {
    $error .=  Name is required. Minimum of 3 characters required in name. ;
}

由于案文领域可以接受任何语言(多种语言),我希望确保PHP能够正确计算UTF-8语言的特性。

这是否足够,或者我是否需要使用其他方法? 令我关切的是,由于某种原因,PHP可能会错失,或者也许我只是冷静,但我不想让人们绕过重要的验证,因为PHP正在错过。

最佳回答

if (mb_strlen($name,  UTF-8 ) < 3) is sufficient enough

确保负责人正确

HTTP-header (Content-Type: text/html; charset=UTF-8)

由于某种原因,还可以检查替代选择。

strlen(utf8_decode($string))

UTF-8至PHP/a>的密码点Array Converter

问题回答

In addition to JapanPro s answer:
Your HTML can have :

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

不是间接的主人声明:

HTTP-header (Content-Type: text/html; charset=UTF-8)




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签