<?php
error_reporting(0);//7all,0no
ini_set('display_errors', '0');
function myerror($errno, $errstr, $errfile, $errline)
{
echo "<BR>error type: [$errno] $errstr<br />\n";
echo "in line $errline of file $errfile<BR>";
}
set_error_handler("myerror");
include("config.php");
$link = mysql_connect($dbhost,$dbuser,$dbpass)
or die("Could not connect : " . mysql_error());
mysql_select_db($dbname) or die("Could not select database");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
//增加人名 insert into `address2` (`sname`) values('人名')
//修改 update `address2` set `sname`='人名' where id='23'
//查询所有的表名 SHOW TABLES from u656b1_db
<form action="" method ......
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)];
}
return $hash;
}
2.截取一定长度的字符串
注:该函数对GB2312使用有效
function wordscut($string, $length ,$sss=0) {
if(strlen($string) > $length) {
if($sss){
$length=$length - 3;
$addstr=' ...';
}
&nbs ......
文件读取函式
//文件读取函式
function PHP_Read($file_name) {
$fd=fopen($file_name,r);
while($bufline=fgets($fd, 4096)){
$buf.=$bufline;
}
fclose($fd);
return $buf;
}
?>
文件写入函式
//文件写入函式
function PHP_Write($file_name,$data,$method="w") {
$filenum=@fopen($file_name,$method);
flock($filenum,LOCK_EX);
$file_data=fwrite($filenum,$data);
fclose($filenum);
return $file_data;
}
?>
静态页面生成函式
//静态页面生成函式
function phptohtm($filefrom,$fileto,$u2u=1){
if($u2u==1){
$data=PHP_Read($filefrom);
}else{
$data=$filefrom;
}
PHP_Write($fileto,$data);
return true;
& ......
如何判断ip地址合法性
if(!strcmp(long2ip(sprintf("%u",ip2long($ip))),$ip)) echo "is ipn";
email的正则判断
eregi("^[_.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z_-]+.)+[a-zA-Z]$", $email);
检测ip地址和mask是否合法的例子
$ip = '192.168.0.84';
$mask = '255.255.255.0';
$network = '192.168.0';
$ip = ip2long($ip);
$mask = ip2long($mask);
$network = ip2long($network);
if( ($ip & $mask) == $network) echo "valid ip and maskn";
?>
文件下载头部输出如何设定
header("Content-type: application/x-download");
header("Content-Disposition: attachment; filename=$file_download_name;");
header("Accept-Ranges: bytes");
header("Content-Length: $download_size");
echo 'xxx'
用header输出ftp下载方式,并且支持断点续传
一个例子:
header('Pragma: public');
header('Cache-Control: private');
header('Cache-Control: no-cache, must-revalidate');
header('Accept-Ranges: bytes');
header('Connection: close');
header("Content-Type: audio/mpeg");
header("Location:ftp://download:1bk3l4s3k9s2@232.2.2 ......
<?php
class useful{
/*
* 常用函数类
* 作 者:多菜鸟
* 联系邮箱:kingerq AT msn DOT com
* 创建时间:2005-07-18
* 来源:http://blog.csdn.net/kingerq
*/
/*
* 功能:格式化数字,以标准MONEY格式输出
*/
function formatnumber($num){
return number_format($num, 2, ".", ",");
}
/*
* 功能:格式化文本,将\n转成<br>等
* 参数:$string 来源字符串
* 返回:处理后的字符串
*/
function formatstring($string = ""){
$string = preg_replace(array("/\s+/", "/\'/"), array(" ", "\"\""), $string);
$string = htmlspecialchars($string);
return nl2br($string);
}
/*
* 功能:格式化文本输出
* 参数 $text 为需格式化的文本内容
* 慎用,如果让用户输入的可执行代码在formatstring处理后插如数据库,然后使用此函数会让代码执行
*/
fun ......
原理
一般,有2种方法可以导出doc文档,一种是使用com,并且作为php的一个扩展库安装到服务器上,然后创建一个com,调用它的方法。安装过office的服务器可以调用一个叫word.application的com,可以生成word文档,不过这种方式我不推荐,因为执行效率比较低(我测试了一下,在执行代码的时候,服务器会真的去打开一个word客户端)。理想的com应该是没有界面的,在后台进行数据转换,这样效果会比较好,但是这些扩展一般需要收费。
第2种方法,就是用PHP将我们的doc文档内容直接写入一个后缀为doc的文件中即可。使用这种方法不需要依赖第三方扩展,而且执行效率较高。
word本身的功能还是很强大的,它可以打开html格式的文件,并且能够保留格式,即使后缀为doc,它也能识别正常打开。这就为我们提供了方便。但是有一个问题,html格式的文件中的图片只有一个地址,真正的图片是保存在其他地方的,也就是说,如果将HTML格式写入doc中,那么doc中将不能包含图片。那我们如何创建包含图片的doc文档呢?我们可以使用和html很接近的mht格式。
mht格式和html很类似,只不过在mht格式中,外部链接进来 ......