-
如何在textarea中显示html代码
XML/HTML代码 新建网页 内容 document.getElementById(“txt”).appendChild(document.getE ...
-
这是一些使用频率比较高的php函数……
1.产生随机字符串函数 function random($length) { $hash = @#@#; $chars = @#abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz@#; $max = strlen($chars) – 1; mt_srand((double)microtime() * 1000000); for($i = 0; $i < $length; $i++) { $hash .= $chars[mt_rand(0, $max)]; } re ...
-
关于DISCUZ不用通行证登陆得内容介绍
关于DISCUZ不用通行证登陆得内容介绍 DISCUZ是中国最常用的论坛,虽然他本身有通行证给大家连接,但实际上用户的统一还是很不好,经常要建立两个用户表,第一不利于注册和管理,第二浪费数据库。 最近做一个项目也是使用的DISCUZ,所以研究了一下DISCUZ的登陆,基本完成了同步登陆。大家如果有兴趣可以研究一下。 别的 ...
-
]不需要mod_rewrite直接使用php实现伪静态化页面
在你的程序初始化时使用如下代码:
PHP代码- $Php2Html_FileUrl = $_SERVER[“REQUEST_URI”];
- $Php2Html_UrlString = str_replace(“/”, “”, strrchr($Php2Html_FileUrl, “/”));
- $Php2Html_UrlQueryStrList = explode(“@”, $Php2Html_UrlString);
- foreach($Php2Html_UrlQueryStrList as $Php2Html_UrlQueryStr)
- {
- $Php2Html_TmpArray = explode(“|”, $Php2Html_UrlQueryStr);
- $_GET[$Php2Html_TmpArray[0]] = $Php2Html_TmpArray[1];
- }
- echo 假静态:$_GET变量
; - print_r($_GET);
- ?>
然后php中调用$_GET变量就像平常一样了。
]]>
连接使用方式:
****.php/param1|1234@param2|4321
和****.php?param1=1234¶m2=4321一样。
-
如何在PHP中读取和写入WORD文档
因为加密等原因,如果直接用FILE后者OPEN等函数读取WORD的话往往是乱码,原来要使用COM
这是我简单的一个读取并存储到新的WORD上的文件
// 建立一个指向新COM组件的索引
$word = new COM(”word.application”) or die(”Can’t start Word!”);
// 显示目前正在使用的Word的版本号
//echo “Loading Word, v. {$word->Version}
”;
// 把它的可见性设置为0(假),如果要使它在最前端打开,使用1(真)
// to open the application in the forefront, use 1 (true)
//$word->Visible = 0;//打?一个文档
$word->Documents->OPen(”d:\myweb\muban.doc”);
//读取文档内容$test= $word->ActiveDocument->content->Text;
echo $test;
echo “
”;//将文档中需要换的变量更换一下
$test=str_replace(”<{变量}>”,”这是变量”,$test);echo $test;
$word->Documents->Add();
// 在新文档中添加文字
$word->Selection->TypeText(”$test”);
//把文档保存在目录中
$word->Documents[1]->SaveAs(”d:/myweb/comtest.doc”);
// 关闭与COM组件之间的连接
$word->Quit();?>
]]>
-
PHP的类,是用来给图片加水印的
]]>PHP代码- /*
- * 功能:PHP图片水印 (水印支持图片或文字)
- * 参数:
- * $groundImage 背景图片,即需要加水印的图片,暂只支持GIF,JPG,PNG格式;
- * $waterPos 水印位置,有10种状态,0为随机位置;
- * 1为顶端居左,2为顶端居中,3为顶端居右;
- * 4为中部居左,5为中部居中,6为中部居右;
- * 7为底端居左,8为底端居中,9为底端居右;
- * $waterImage 图片水印,即作为水印的图片,暂只支持GIF,JPG,PNG格式;
- * $waterText 文字水印,即把文字作为为水印,支持ASCII码,不支持中文;
- * $textFont 文字大小,值为1、2、3、4或5,默认为5;
- * $textColor 文字颜色,值为十六进制颜色值,默认为#FF0000(红色);
- *
- * 注意:Support GD 2.0,Support FreeType、GIF Read、GIF Create、JPG 、PNG
- * $waterImage 和 $waterText 最好不要同时使用,选其中之一即可,优先使用 $waterImage。
- * 当$waterImage有效时,参数$waterString、$stringFont、$stringColor均不生效。
- * 加水印后的图片的文件名和 $groundImage 一样。
- * 作者:longware @ 2004-11-3 14:15:13
- */
- function imageWaterMark($groundImage,$waterPos=0,$waterImage=”“,$waterText=””,$textFont=5,$textColor=”#FF0000″)
- {
- $isWaterImage = FALSE;
- $formatMsg = “暂不支持该文件格式,请用图片处理软件将图片转换为GIF、JPG、PNG格式。”;
- //读取水印文件
- if(!emptyempty($waterImage) && file_exists($waterImage))
- {
- $isWaterImage = TRUE;
- $water_info = getimagesize($waterImage);
- $water_w = $water_info[0];//取得水印图片的宽
- $water_h = $water_info[1];//取得水印图片的高
- switch($water_info[2])//取得水印图片的格式
- {
- case 1:$water_im = imagecreatefromgif($waterImage);break;
- case 2:$water_im = imagecreatefromjpeg($waterImage);break;
- case 3:$water_im = imagecreatefrompng($waterImage);break;
- default:die($formatMsg);
- }
- }
- //读取背景图片
- if(!emptyempty($groundImage) && file_exists($groundImage))
- {
- $ground_info = getimagesize($groundImage);
- $ground_w = $ground_info[0];//取得背景图片的宽
- $ground_h = $ground_info[1];//取得背景图片的高
- switch($ground_info[2])//取得背景图片的格式
- {
- case 1:$ground_im = imagecreatefromgif($groundImage);break;
- case 2:$ground_im = imagecreatefromjpeg($groundImage);break;
- case 3:$ground_im = imagecreatefrompng($groundImage);break;
- default:die($formatMsg);
- }
- }
- else
- {
- die(”需要加水印的图片不存在!”);
- }
- //水印位置
- if($isWaterImage)//图片水印
- {
- $w = $water_w;
- $h = $water_h;
- $label = “图片的”;
- }
- else//文字水印
- {
- $temp = imagettfbbox(ceil($textFont*5),0,”./cour.ttf”,$waterText);//取得使用 TrueType 字体的文本的范围
- $w = $temp[2] – $temp[6];
- $h = $temp[3] – $temp[7];
- unset($temp);
- $label = “文字区域”;
- }
- if( ($ground_w<$w) || ($ground_h<$h) )
- {
- echo “需要加水印的图片的长度或宽度比水印”.$label.”还小,无法生成水印!”;
- return;
- }
- switch($waterPos)
- {
- case 0://随机
- $posX = rand(0,($ground_w – $w));
- $posY = rand(0,($ground_h – $h));
- break;
- case 1://1为顶端居左
- $posX = 0;
- $posY = 0;
- break;
- case 2://2为顶端居中
- $posX = ($ground_w – $w) / 2;
- $posY = 0;
- break;
- case 3://3为顶端居右
- $posX = $ground_w – $w;
- $posY = 0;
- break;
- case 4://4为中部居左
- $posX = 0;
- $posY = ($ground_h – $h) / 2;
- break;
- case 5://5为中部居中
- $posX = ($ground_w – $w) / 2;
- $posY = ($ground_h – $h) / 2;
- break;
- case 6://6为中部居右
- $posX = $ground_w – $w;
- $posY = ($ground_h – $h) / 2;
- break;
- case 7://7为底端居左
- $posX = 0;
- $posY = $ground_h – $h;
- break;
- case 8://8为底端居中
- $posX = ($ground_w – $w) / 2;
- $posY = $ground_h – $h;
- break;
- case 9://9为底端居右
- $posX = $ground_w – $w;
- $posY = $ground_h – $h;
- break;
- default://随机
- $posX = rand(0,($ground_w – $w));
- $posY = rand(0,($ground_h – $h));
- break;
- }
- //设定图像的混色模式
- imagealphablending($ground_im, true);
- if($isWaterImage)//图片水印
- {
- imagecopy($ground_im, $water_im, $posX, $posY, 0, 0, $water_w,$water_h);//拷贝水印到目标文件
- }
- else//文字水印
- {
- if( !emptyempty($textColor) && (strlen($textColor)==7) )
- {
- $R = hexdec(substr($textColor,1,2));
- $G = hexdec(substr($textColor,3,2));
- $B = hexdec(substr($textColor,5));
- }
- else
- {
- die(”水印文字颜色格式不正确!”);
- }
- imagestring ( $ground_im, $textFont, $posX, $posY, $waterText, imagecolorallocate($ground_im, $R, $G, $B));
- }
- //生成水印后的图片
- @unlink($groundImage);
- switch($ground_info[2])//取得背景图片的格式
- {
- case 1:imagegif($ground_im,$groundImage);break;
- case 2:imagejpeg($ground_im,$groundImage);break;
- case 3:imagepng($ground_im,$groundImage);break;
- default:die($errorMsg);
- }
- //释放内存
- if(isset($water_info)) unset($water_info);
- if(isset($water_im)) imagedestroy($water_im);
- unset($ground_info);
- imagedestroy($ground_im);
- }
- //—————————————————————————————
- $id=$_REQUEST[’id’];
- $num = count($_FILES[’userfile’][’name’]);
- print_r($_FILES[’userfile’]);
- print_r($_FILES[’userfile’][’name’]);
- echo $num;
- echo “
”; - if(isset($id)){
- for($i=0;$i<$id;$i++){
- if(isset($_FILES) && !emptyempty($_FILES[’userfile’]) && $_FILES[’userfile’][’size’]>0)
- {
- $uploadfile = “./”.time().”_”.$_FILES[’userfile’][name][$i];
- echo “
”; - echo $uploadfile;
- if (copy($_FILES[’userfile’][’tmp_name’][$i], $uploadfile))
- {
- echo “OK
”; - //文字水印
- //imageWaterMark($uploadfile,5,””,”HTTP://www.lvye.info”,5,”#cccccc“);
- //图片水印
- $waterImage=”logo_ok1.gif”;//水印图片路径
- imageWaterMark($uploadfile,9,$waterImage);
- echo “$uploadfile.”\” border=\”0\”>”;
- }
- else
- {
- echo “Fail
”; - }
- }
- }
- }
- ?>
- for($a=0;$a<$id;$a++){
- echo “文件:
”; - }
- ?>
-
PHP提取中文首字母
从别人程序中扒拉出来的不是原创。Dzender的代码学习用
PHP代码- function pykey( $py_key)
- {
- $pinyin = 65536 + pys($py_key);
- if ( 45217 <= $pinyin && $pinyin <= 45252 )
- {
- $zimu = “A”;
- return $zimu;
- }
- if ( 45253 <= $pinyin && $pinyin <= 45760 )
- {
- $zimu = “B”;
- return $zimu;
- }
- if ( 45761 <= $pinyin && $pinyin <= 46317 )
- {
- $zimu = “C”;
- return $zimu;
- }
- if ( 46318 <= $pinyin && $pinyin <= 46825 )
- {
- $zimu = “D”;
- return $zimu;
- }
- if ( 46826 <= $pinyin && $pinyin <= 47009 )
- {
- $zimu = “E”;
- return $zimu;
- }
- if ( 47010 <= $pinyin && $pinyin <= 47296 )
- {
- $zimu = “F”;
- return $zimu;
- }
- if ( 47297 <= $pinyin && $pinyin <= 47613 )
- {
- $zimu = “G”;
- return $zimu;
- }
- if ( 47614 <= $pinyin && $pinyin <= 48118 )
- {
- $zimu = “H”;
- return $zimu;
- }
- if ( 48119 <= $pinyin && $pinyin <= 49061 )
- {
- $zimu = “J”;
- return $zimu;
- }
- if ( 49062 <= $pinyin && $pinyin <= 49323 )
- {
- $zimu = “K”;
- return $zimu;
- }
- if ( 49324 <= $pinyin && $pinyin <= 49895 )
- {
- $zimu = “L”;
- return $zimu;
- }
- if ( 49896 <= $pinyin && $pinyin <= 50370 )
- {
- $zimu = “M”;
- return $zimu;
- }
- if ( 50371 <= $pinyin && $pinyin <= 50613 )
- {
- $zimu = “N”;
- return $zimu;
- }
- if ( 50614 <= $pinyin && $pinyin <= 50621 )
- {
- $zimu = “O”;
- return $zimu;
- }
- if ( 50622 <= $pinyin && $pinyin <= 50905 )
- {
- $zimu = “P”;
- return $zimu;
- }
- if ( 50906 <= $pinyin && $pinyin <= 51386 )
- {
- $zimu = “Q”;
- return $zimu;
- }
- if ( 51387 <= $pinyin && $pinyin <= 51445 )
- {
- $zimu = “R”;
- return $zimu;
- }
- if ( 51446 <= $pinyin && $pinyin <= 52217 )
- {
- $zimu = “S”;
- return $zimu;
- }
- if ( 52218 <= $pinyin && $pinyin <= 52697 )
- {
- $zimu = “T”;
- return $zimu;
- }
- if ( 52698 <= $pinyin && $pinyin <= 52979 )
- {
- $zimu = “W”;
- return $zimu;
- }
- if ( 52980 <= $pinyin && $pinyin <= 53640 )
- {
- $zimu = “X”;
- return $zimu;
- }
- if ( 53689 <= $pinyin && $pinyin <= 54480 )
- {
- $zimu = “Y”;
- return $zimu;
- }
- if ( 54481 <= $pinyin && $pinyin <= 62289 )
- {
- $zimu = “Z”;
- return $zimu;
- }
- $zimu = $py_key;
- return $zimu;
- }
- function pys( $pysa )
- {
- $pyi = “”;
- $i= 0;
- for ( ; $i < strlen( $pysa ); $i++)
- {
- $_obfuscate_8w= ord( substr( $pysa,$i,1) );
- if ( 160 < $_obfuscate_8w)
- {
- $_obfuscate_Bw = ord( substr( $pysa, $i++, 1 ) );
- $_obfuscate_8w = $_obfuscate_8w * 256 + $_obfuscate_Bw – 65536;
- }
- $pyi.= $_obfuscate_8w;
- }
- return $pyi;
- }
- $letter = pykey(“中华人民共和国”);
- echo $letter;
- ?>
-
从discuz里面拿来的东东[转phpx]
加解密函数 $encode = authocode(‘我要加密’,‘ENCODE’); $decode = authocode(‘我要解密’,‘DECODE’);
$auth_key = 34577 ; //密钥
function authcode($string, $operation, $key = ”) { $key = md5($key ? $key : $GLOBALS[‘auth_key’]);
$key_length = strlen($key); $string = $operation == ‘DECODE’ ? base64_decode($string) : substr(md5($string.$key), 0, 8).$string;
$string_length = strlen($string); $rndkey = $box = array();
$result = ”; for($i = 0; $i <= 255; $i++) {
$rndkey[$i] = ord($key[$i % $key_length]);
$box[$i] = $i;
} for($j = $i = 0; $i < 256; $i++) {
$j = ($j + $box[$i] + $rndkey[$i]) % 256;
$tmp = $box[$i];
$box[$i] = $box[$j];
$box[$j] = $tmp;
} for($a = $j = $i = 0; $i < $string_length; $i++) {
$a = ($a + 1) % 256;
$j = ($j + $box[$a]) % 256;
$tmp = $box[$a];
$box[$a] = $box[$j];
$box[$j] = $tmp;
$result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
} if($operation == ‘DECODE’) {
if(substr($result, 0, 8) == substr(md5(substr($result, 8).$key), 0, 8)) {
return substr($result, 8);
} else {
return ”;
}
} else {
return str_replace(‘=’, ”, base64_encode($result));
} } ?>字符串截取函数 $cutstr = cutstr(‘截取我,hahahahahaaha’,‘3’); function cutstr($string, $length, $dot = ‘ …’) {
global $charset; if(strlen($string) <= $length) {
return $string;
} $string = str_replace(array(‘&’, ‘"’, ‘<‘, ‘>’), array(‘&’, ‘”‘, ‘<', ‘>’), $string); $strcut = ”;
if(strtolower($charset) == ‘utf-8’) { $n = $tn = $noc = 0;
while($n < strlen($string)) { $t = ord($string[$n]);
if($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) {
$tn = 1; $n++; $noc++;
} elseif(194 <= $t && $t <= 223) {
$tn = 2; $n += 2; $noc += 2;
} elseif(224 <= $t && $t < 239) {
$tn = 3; $n += 3; $noc += 2;
} elseif(240 <= $t && $t <= 247) {
$tn = 4; $n += 4; $noc += 2;
} elseif(248 <= $t && $t <= 251) {
$tn = 5; $n += 5; $noc += 2;
} elseif($t == 252 || $t == 253) {
$tn = 6; $n += 6; $noc += 2;
} else {
$n++;
} if($noc >= $length) {
break;
} }
if($noc > $length) {
$n -= $tn;
} $strcut = substr($string, 0, $n); } else {
for($i = 0; $i < $length – strlen($dot) – 1; $i++) {
$strcut .= ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i];
}
} $strcut = str_replace(array(‘&’, ‘”‘, ‘<', ‘>’), array(‘&’, ‘"’, ‘<‘, ‘>’), $strcut); return $strcut.$dot;
}
function daddslashes($string, $force = 0) {
!defined(‘MAGIC_QUOTES_GPC’) && define(‘MAGIC_QUOTES_GPC’, get_magic_quotes_gpc());
if(!MAGIC_QUOTES_GPC || $force) {
if(is_array($string)) {
foreach($string as $key => $val) {
$string[$key] = daddslashes($val, $force);
}
} else {
$string = addslashes($string);
}
}
return $string;
}
?>function random($length, $numeric = 0) {
PHP_VERSION < ‘4.2.0’ && mt_srand((double)microtime() * 1000000);
if($numeric) {
$hash = sprintf(‘%0’.$length.‘d’, mt_rand(0, pow(10, $length) – 1));
} else {
$hash = ”;
$chars = ‘ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz’;
$max = strlen($chars) – 1;
for($i = 0; $i < $length; $i++) {
$hash .= $chars[mt_rand(0, $max)];
}
}
return $hash;
}
?>// discuz 一个ip转换地址的函数 wry.dat 是ip数据库 可以从纯真网下载最新的 [url]http://www.cz88.net/[/url] function convertip($ip) {]]>
if(!preg_match(“/^d{1,3}.d{1,3}.d{1,3}.d{1,3}$/”, $ip)) {
return ”;
} if($fd = @fopen(DISCUZ_ROOT.‘./ipdata/wry.dat’, ‘rb’)) { $ip = explode(‘.’, $ip);
$ipNum = $ip[0] * 16777216 + $ip[1] * 65536 + $ip[2] * 256 + $ip[3]; $DataBegin = fread($fd, 4);
$DataEnd = fread($fd, 4);
$ipbegin = implode(”, unpack(‘L’, $DataBegin));
if($ipbegin < 0) $ipbegin += pow(2, 32);
$ipend = implode(”, unpack(‘L’, $DataEnd));
if($ipend < 0) $ipend += pow(2, 32);
$ipAllNum = ($ipend – $ipbegin) / 7 + 1; $BeginNum = 0;
$EndNum = $ipAllNum; while($ip1num > $ipNum || $ip2num < $ipNum) {
$Middle= intval(($EndNum + $BeginNum) / 2); fseek($fd, $ipbegin + 7 * $Middle);
$ipData1 = fread($fd, 4);
if(strlen($ipData1) < 4) {
fclose($fd);
return ‘System Error’;
}
$ip1num = implode(”, unpack(‘L’, $ipData1));
if($ip1num < 0) $ip1num += pow(2, 32); if($ip1num > $ipNum) {
$EndNum = $Middle;
continue;
} $DataSeek = fread($fd, 3);
if(strlen($DataSeek) < 3) {
fclose($fd);
return ‘System Error’;
}
$DataSeek = implode(”, unpack(‘L’, $DataSeek.chr(0)));
fseek($fd, $DataSeek);
$ipData2 = fread($fd, 4);
if(strlen($ipData2) < 4) {
fclose($fd);
return ‘System Error’;
}
$ip2num = implode(”, unpack(‘L’, $ipData2));
if($ip2num < 0) $ip2num += pow(2, 32); if($ip2num < $ipNum) {
if($Middle == $BeginNum) {
fclose($fd);
return ‘Unknown’;
}
$BeginNum = $Middle;
}
} $ipFlag = fread($fd, 1);
if($ipFlag == chr(1)) {
$ipSeek = fread($fd, 3);
if(strlen($ipSeek) < 3) {
fclose($fd);
return ‘System Error’;
}
$ipSeek = implode(”, unpack(‘L’, $ipSeek.chr(0)));
fseek($fd, $ipSeek);
$ipFlag = fread($fd, 1);
} if($ipFlag == chr(2)) {
$AddrSeek = fread($fd, 3);
if(strlen($AddrSeek) < 3) {
fclose($fd);
return ‘System Error’;
}
$ipFlag = fread($fd, 1);
if($ipFlag == chr(2)) {
$AddrSeek2 = fread($fd, 3);
if(strlen($AddrSeek2) < 3) {
fclose($fd);
return ‘System Error’;
}
$AddrSeek2 = implode(”, unpack(‘L’, $AddrSeek2.chr(0)));
fseek($fd, $AddrSeek2);
} else {
fseek($fd, –1, SEEK_CUR);
} while(($char = fread($fd, 1)) != chr(0))
$ipAddr2 .= $char; $AddrSeek = implode(”, unpack(‘L’, $AddrSeek.chr(0)));
fseek($fd, $AddrSeek); while(($char = fread($fd, 1)) != chr(0))
$ipAddr1 .= $char;
} else {
fseek($fd, –1, SEEK_CUR);
while(($char = fread($fd, 1)) != chr(0))
$ipAddr1 .= $char; $ipFlag = fread($fd, 1);
if($ipFlag == chr(2)) {
$AddrSeek2 = fread($fd, 3);
if(strlen($AddrSeek2) < 3) {
fclose($fd);
return ‘System Error’;
}
$AddrSeek2 = implode(”, unpack(‘L’, $AddrSeek2.chr(0)));
fseek($fd, $AddrSeek2);
} else {
fseek($fd, –1, SEEK_CUR);
}
while(($char = fread($fd, 1)) != chr(0))
$ipAddr2 .= $char;
}
fclose($fd); if(preg_match(‘/http/i’, $ipAddr2)) {
$ipAddr2 = ”;
}
$ipaddr = “$ipAddr1 $ipAddr2”;
$ipaddr = preg_replace(‘/CZ88.NET/is’, ”, $ipaddr);
$ipaddr = preg_replace(‘/^s*/is’, ”, $ipaddr);
$ipaddr = preg_replace(‘/s*$/is’, ”, $ipaddr);
if(preg_match(‘/http/i’, $ipaddr) || $ipaddr == ”) {
$ipaddr = ‘Unknown’;
} return $ipaddr; } else { $datadir = DISCUZ_ROOT.‘./ipdata/’;
$ip_detail = explode(‘.’, $ip);
if(file_exists($datadir.$ip_detail[0].‘.txt’)) {
$ip_fdata = @fopen($datadir.$ip_detail[0].‘.txt’, ‘r’);
} else {
if(!($ip_fdata = @fopen($datadir.‘0.txt’, ‘r’))) {
return ‘Invalid IP data file’;
}
}
for ($i = 0; $i <= 3; $i++) {
$ip_detail[$i] = sprintf(‘%03d’, $ip_detail[$i]);
}
$ip = join(‘.’, $ip_detail);
do {
$ip_data = fgets($ip_fdata, 200);
$ip_data_detail = explode(‘|’, $ip_data);
if($ip >= $ip_data_detail[0] && $ip <= $ip_data_detail[1]) {
fclose($ip_fdata);
return $ip_data_detail[2].$ip_data_detail[3];
}
} while(!feof($ip_fdata));
fclose($ip_fdata);
return ‘UNKNOWN’; } }
?>