php

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...

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

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

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 !==...

给图片加水印类

set_time_limit(3000); class GDMark { var $sourcePath; //图片存储路径 var $galleryPath; //图片缩略图存储路径 var $toFile = false; //是否生成文件 var $WaterPos; var $MarkSign = null; var $fontName; //使用的TTF字体名称 var $maxWidth = 600; //图片最大宽度 var $maxHeight = 700; //图片最大高度function GDMark($sourcePath, $galleryPath, $WaterPos, $fontPath, $MarkSign='') { $this->sourcePath = $sourcePath; $this->galleryPath =...

[GD]生成bmp格式的图片(imagebmp)

GD库里没有生成bmp图片的函数,所以自己写了一个,这个函数尚有一个压缩算法没有写,不过已经够用了。需要的同学可以看看。int imagebmp ( resource image [, string filename [, int $bit [, int compression]]] )$im: 图像资源$filename: 如果要另存为文件,请指定文件名,为空则直接在浏览器输出$bit: 图像质量(1、4、8、16、24、32位)$compression:...

php水印加强版

文件: ...