php随机码

/* * 说明:生成随机码,并用图形方式显示随机码。 */$ViewRandomCode = mt_rand(1000,10000);session_start(); $_SESSION['checksum'] = $ViewRandomCode;function set_4pixel($r, $g, $b, $x, $y) { global $sx, $sy, $pixels;$ofs = 3 * ($sx * $y + $x); $pixels[$ofs] = chr($r); $pixels[$ofs + 1] = chr($g); $pixels[$ofs + 2] = chr($b); $pixels[$ofs + 3] = chr($r); $pixels[$ofs + 4] = chr($g); $pixels[$ofs + 5] = chr($b); $ofs += 3 * $sx; $pixels[$ofs] =...

php验证码

实现上下左右随即浮动,字符+数字,随机干扰线 ,作者不详session_start(); $image = imagecreatetruecolor(58,22); $color_Background = imagecolorallocate($image,255,255,255); imagefill($image,0,0,$color_Background); $key =...

UTF-8 GBK下PHP获取字符串长度

UTF-8 GBK下PHP获取字符串长度,是langwan写的,贴过来大家分享,完美的解决了PHP下获取UTF-8或者GBK字符集的字符串长度问题!/** 统计字符串长度 *@author langwan *@param $str 被统计字符串*/function sstrlen($str) { global $charset; $n = 0; $p = 0; $c = ''; $len = strlen($str); if($charset == 'utf-8') { for($i = 0; $i < $len; $i++) { $c = ord($str{$i}); if($c > 252) { $p = 5; } elseif($c > 248) { $p = 4; }...

中文字符长度

//中文字符长度,一个中文长度为1。 function cstrlen($str){ $n = 0; $p = 0; $c = ''; $len = strlen($str);for($i = 0; $i < $len; $i++) { $c = ord($str{$i}); if($c > 127) { $p = 1; } else { $p = 0; } $i+=$p;$n++; }return...

截取字符串-InterceptString

'************* 截取字符串 **************function InterceptString(txt,length) txt=trim(txt) x = len(txt) y = 0 if x >= 1 then for ii = 1 to x if asc(mid(txt,ii,1)) < 0 or asc(mid(txt,ii,1)) >255 then '如果是汉字 y = y + 2 else y = y + 1 end if if y >= length then txt = left(trim(txt),ii) '字符串限长 exit for end if next InterceptString = txt else InterceptString = "" end ifEnd...

测字符串长度-CheckStringLength

'*************测字符串长度**************Function CheckStringLength(txt) txt=trim(txt) x = len(txt) y = 0 for ii = 1 to x if asc(mid(txt,ii,1)) < 0 or asc(mid(txt,ii,1)) >255 then '如果是汉字 y = y + 2 else y = y + 1 end if next CheckStringLength = yEnd...

用PHP生成随机数(另附PHP随机函数)

通常情况下,当我们要生成一个随机字符串时,总是先创建一个字符池,然后用一个循环和mt_rand()或rand()生成php随机数,从字符池中随机选取字符,最后拼凑出需要的长度。 function randomkeys($length){ $pattern = '1234567890abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLOMNOPQRSTUVWXYZ,./&l t;>?;#:@~[]{}-_=+)(*&^%___FCKpd___0pound;"!'; //字符池 for($i=0;$i<$length;$i++) { $key .=...

UTF8编码转Unicode

function Utf8ToUnicode(strUtf8) { var bstr = ""; var nTotalChars = strUtf8.length; // total chars to be processed. var nOffset = 0; // processing point on strUtf8 var nRemainingBytes = nTotalChars; // how many bytes left to be converted var nOutputPosition = 0; var iCode, iCode1, iCode2; // the value of the unicode.while (nOffset < nTotalChars) { iCode = strUtf8.charCodeAt(nOffset); if ((iCode &...

SureRemoveDir-删除目录

// ggarciaa at gmail dot com (04-July-2007 01:57) // I needed to empty a directory, but keeping it // so I slightly modified the contribution from // stefano at takys dot it (28-Dec-2005 11:57) // A short but powerfull recursive function // that works also if the dirs contain hidden files // // $dir = the target directory // $DeleteMe = if true delete also $dir, if false leave it alonefunction SureRemoveDir($dir, $DeleteMe) { if(!$dh = @opendir($dir)) return; while (false !==...