Home  >  Article  >  Backend Development  >  中文验证码如何选取

中文验证码如何选取

WBOY
WBOYOriginal
2016-06-13 13:20:081162browse

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

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


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

Statement:
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