Home Backend Development PHP Tutorial 中文验证码如何选取

中文验证码如何选取

Jun 13, 2016 am 10:37 AM
iconv rand

中文验证码怎么选取?
英文验证码用的是定义26个大小写字母加数字的数组随机下标来获得随机的验证码 
请问中文验证码要怎么获得随机的中文?同英文一样定义中文的数组的话会不会太大?

------解决方案--------------------
注意到汉字的 UCS-2 编码从 0x4e00 到 0x9fa6 是连续的
所以你只需
$ch = iconv('ucs-2', 'utf-8', pack('n', rand(0x4e00, 0x9fa6)));
就可随机得到一个汉字


------解决方案--------------------
建一个常用字库,而且验证功能不需要列举所有常用字

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve 'undefined: rand.Seed' error in golang? How to solve 'undefined: rand.Seed' error in golang? Jun 25, 2023 am 08:34 AM

During the development or learning process of using Golang, we may encounter the error message of undefined:rand.Seed. This error usually occurs when you need to use a random number generator, because in Golang you need to set a random number seed before you can use the function in the rand package. This article will explain how to resolve this error. 1. Introduce the math/rand package. First, we need to introduce the math/rand package into the code. exist

Recommended essential functions for Chinese processing: Detailed explanation of PHP iconv function Recommended essential functions for Chinese processing: Detailed explanation of PHP iconv function Jun 27, 2023 pm 02:04 PM

In the process of text processing, it is a common requirement to convert strings in different encoding formats. The iconv (InternationalizationConversion) function provided in the PHP language can meet this need very conveniently. This article will introduce the use of iconv function in detail from the following aspects: Definition of iconv function and introduction to common parameters Example demonstration: Convert GBK encoded string to UTF-8 encoded string Example demonstration: Convert UTF

How to synchronize random number generation in Golang parallel processing? How to synchronize random number generation in Golang parallel processing? Jun 03, 2024 pm 02:53 PM

Synchronizing random number generation in Go concurrent programming: Use a mutex (sync.Mutex) to control access to the rand.Rand random number generator. Each goroutine acquires the mutex lock before generating random numbers and releases the mutex lock after generating it. This ensures that only one goroutine can access the random number generator at a time, eliminating data races.

Introduction to iconv command under CentOS Introduction to iconv command under CentOS Dec 29, 2023 pm 07:52 PM

iconv-fencoding[-tencoding][inputfile]...[Function] Converts the contents of a given file from one encoding to another. [Description]-fencoding: Convert characters from encoding to encoding. -tencoding: Convert characters to encoding. -l: List the known set of encoded characters -ofile: Specify the output file -c: Ignore illegal characters in the output -s: Suppress warning messages, but not error messages --verbose: Display progress information -f and -t can The specified legal characters are listed in the command with the -l option. [Example]* List currently supported character encodings

How to solve the problem of generating the same random numbers using php rand function How to solve the problem of generating the same random numbers using php rand function Mar 23, 2023 am 09:17 AM

The rand() function uses the same initial seeds on each call. The default initial seed is obtained from the operating system's time, but it only has microsecond accuracy. That is, within a very short period of time, many rand() function calls will use the same initial seed, resulting in the same random number generation. So, how to solve this problem?

Research and analysis of randomness of rand function in PHP Research and analysis of randomness of rand function in PHP Mar 12, 2024 pm 07:09 PM

Research and analysis of randomness of rand function in PHP Random numbers are widely used in computer programming, and the rand function in PHP is one of the common methods used to generate random integers. This article will explore the randomness of the rand function in PHP and analyze its characteristics of generating random numbers through specific code examples. 1. Introduction to the rand function in PHP In PHP, the rand function can be used to generate random integers within a specified range. Its basic syntax is as follows: intrand(int$min

In C/C++, rand() and srand() are translated as follows: In C/C++, rand() and srand() are translated as follows: Sep 05, 2023 pm 03:25 PM

In this article, we will discuss the working principle, syntax and examples of rand() and srand() functions in C++STL. What is rand()? The rand() function is a built-in function in C++STL and is defined in the header file. rand() is used to generate a series of random numbers. We can use this function when we want to generate random numbers in code. Just like when we make ludo game in C++, we have to generate any random number between 1 and 6, so we can use rand() to generate the random number. Random numbers are generated using an algorithm that gives a sequence of uncorrelated numbers whenever this function is called. Just like we want to generate a random number between 1-6, we can use

Better random numbers in PHP Better random numbers in PHP Mar 21, 2024 am 11:12 AM

This article will explain in detail about better random numbers in PHP. The editor thinks it is quite practical, so I share it with you as a reference. I hope you can gain something after reading this article. Overview of PHP random number generation PHP provides a variety of functions for generating random numbers, including: mt_rand() function family mt_rand(): Generates a pseudo-random integer within a given range. mt_srand() and mt_srand_mt(): Set the mother number and initialize the random number generator. mt_getrandmax(): Returns the maximum possible output of the generator. rand() function family rand(): generates a pseudo-random integer between 0 and RAND_MAX. sran

See all articles