日历
| |||||||||
| 日 | 一 | 二 | 三 | 四 | 五 | 六 | |||
| 1 | 2 | 3 | 4 | ||||||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 | |||
| 12 | 13 | 14 | 15 | 16 | 17 | 18 | |||
| 19 | 20 | 21 | 22 | 23 | 24 | 25 | |||
| 26 | 27 | 28 | 29 | 30 | 31 | ||||
搜索标题
最新来客
最新评论
统计信息
- 访问量: 2902
- 日志数: 25
- 建立时间: 2007-04-19
- 更新时间: 2008-04-14
我的最新日志
-
刚写的数据库备份&&恢复类
2008-4-14
很简单的一个数据库资料备份和恢复类
使用方法:
[php]
简单备份(直接输出)
$dbbak=new Dbbak($model);
echo $dbbak->Backup('ill');//一个表//echo $dbbak->Backup(array('table1','table2'));//几个表
备份到文件
$dbbak=new Dbbak($model);
$dbbak->Backuptofile($table,'文件名');
恢复数据(由sql语句)
$dbbak=new Dbbak($model);
$dbbak->Restore($table,'',$content);
从文件恢复数据
$dbbak=new Dbbak($model);
$file="data.sql";
$dbbak->Restore($table,$file,'');
[/php]
类具体代码
[php]
<?php
class Dbbak
{
var $obj;
//传进来的model,model可以是fleaphp里面的,也可以是你自己的数据库操作类的实例
//如果用的是你自己的数据库类,findBySql方法为执行sql语句,并返回结果集
//execute则是直接执行sql语句,无返回值
function Dbbak($model)
{
$this->obj=$model;
}
function Backup($table)
{
if(is_array ($table))
{
$str="";
foreach($table as $tab)
$str.=$this->get_table_content($tab);
return $str;
}else{
return $this->get_table_content($table);
}
}
function Backuptofile($table,$file)
{
header("Content-disposition: filename=$file.sql");//所保存的文件名
header("Content-type: application/octetstream");
header("Pragma: no-cache");
header("Expires: 0");
if(is_array ($table))
{
$str="";
foreach($table as $tab)
$str.=$this->get_table_content($tab);
echo $str;
}else{
echo $this->get_table_content($table);
}
}
function Restore($table,$file="",$content="")
{
//排除file,content都为空或者都不为空的情况
if(($file==""&&$content=="")||($file!=""&&$content!=""))
echo"参数错误";
$this->truncate($table);
if($file!="")
{
if($this->RestoreFromFile($file))
return true;
else
return false;
}
if($content!="")
{
if($this->RestoreFromContent($content))
return true;
else
return false;}
}
//清空表,以便恢复数据
function truncate($table)
{
if(is_array ($table))
{
$str="";
foreach($table as $tab)
$this->obj->execute("TRUNCATE TABLE $tab");
}else{
$this->obj->execute("TRUNCATE TABLE $table");
}}
function get_table_content($table)
{
$results=$this->obj->findBySql("select * from $table");
$temp = "";
$crlf="\r\n";
foreach($results as $result)
{ $schema_insert = "INSERT INTO $table VALUES (";
foreach($result as $key=>$val)
{
if($val != "")
$schema_insert .= " '".addslashes($val)."',";
else
$schema_insert .= "NULL,";
}
$schema_insert = ereg_replace(",$", "", $schema_insert);
$schema_insert .= ");$crlf";
$temp = $temp.$schema_insert ;
}
return $temp;
}function RestoreFromFile($file){
if (false !== ($fp = fopen($file, 'r'))) {
$sql_queries = trim(fread($fp, filesize($file)));
$this->splitMySqlFile($pieces, $sql_queries);
foreach ($pieces as $query) {
if(!$this->obj->execute($query))
return false;
}
return true;
}
return false;
}
function RestoreFromContent($content)
{
$content = trim($content);
$this->splitMySqlFile($pieces, $sql_queries);
foreach ($pieces as $query) {
if(!$this->obj->execute($query))
return false;
}
return true;
}
//来自phpmyadmin的函数
function splitMySqlFile(&$ret, $sql)
{
$sql = trim($sql);
$sql_len = strlen($sql);
$char = '';
$string_start = '';
$in_string = false;for ($i = 0; $i < $sql_len; ++$i) {
$char = $sql[$i];// We are in a string, check for not escaped end of
// strings except for backquotes that can't be escaped
if ($in_string) {
for (;;) {
$i = strpos($sql, $string_start, $i);
// No end of string found -> add the current
// substring to the returned array
if (!$i) {
$ret[] = $sql;
return true;
}
// Backquotes or no backslashes before
// quotes: it's indeed the end of the
// string -> exit the loop
else if ($string_start == '`' || $sql[$i-1] != '\\') {
$string_start = '';
$in_string = false;
break;
}
// one or more Backslashes before the presumed
// end of string...
else {
// first checks for escaped backslashes
$j = 2;
$escaped_backslash = false;
while ($i-$j > 0 && $sql[$i-$j] == '\\') {
$escaped_backslash = !$escaped_backslash;
$j++;
}
// ... if escaped backslashes: it's really the
// end of the string -> exit the loop
if ($escaped_backslash) {
$string_start = '';
$in_string = false;
break;
}
// ... else loop
else {
$i++;}
} // end if...elseif...else
} // end for
} // end if (in string)
// We are not in a string, first check for delimiter...
else if ($char == ';') {
// if delimiter found, add the parsed part to the returned array
$ret[] = substr($sql, 0, $i);
$sql = ltrim(substr($sql, min($i + 1, $sql_len)));
$sql_len = strlen($sql);
if ($sql_len) {
$i = -1;
} else {
// The submited statement(s) end(s) here
return true;
}
} // end else if (is delimiter)
// ... then check for start of a string,...
else if (($char == '"') || ($char == '\'') || ($char == '`')) {
$in_string = true;
$string_start = $char;
} // end else if (is start of string)// for start of a comment (and remove this comment if found)...
else if ($char == '#' || ($char == ' ' && $i > 1 && $sql[$i-2] . $sql[$i-1] == '--')) {
// starting position of the comment depends on the comment type
$start_of_comment = (($sql[$i] == '#') ? $i : $i-2);
// if no "\n" exits in the remaining string, checks for "\r"
// (Mac eol style)
$end_of_comment = (strpos(' ' . $sql, "\012", $i+2))
? strpos(' ' . $sql, "\012", $i+2)
: strpos(' ' . $sql, "\015", $i+2);
if (!$end_of_comment) {
// no eol found after '#', add the parsed part to the returned
// array and exit
// RMV fix for comments at end of file
$last = trim(substr($sql, 0, $i-1));
if (!empty($last)) {
$ret[] = $last;
}
return true;
} else {
$sql = substr($sql, 0, $start_of_comment) . ltrim(substr($sql, $end_of_comment));
$sql_len = strlen($sql);
$i--;
} // end if...else
} // end else if (is comment)
} // end for// add any rest to the returned array
if (!empty($sql) && trim($sql) != '') {
$ret[] = $sql;
}
return true;
}
}
?>
[/php] -
关于存储多个复选框的一点经验
2008-4-13
1.形如这样例子的存储
1.jpg
每个人建个字段的话太麻烦,操作起来太费事
数据库这样建:
是否有高血压:havegaoxueya
有高血压的的人:havegaoxueyaer
。。。
保存的时候
读取的时候 -
php注册码解决方案?
2008-4-13
帮人做的一个项目,要求添加注册码功能(形如那些共享软件)
要求一台电脑对应唯一的key,这样就能有效的保护版权,就算把程序拷贝到其他电脑,没有key也使用不了,下面是我的思路,不知道大虾们有什么好的解决方案?
我是这样考虑的:
1、通过php获取电脑(服务器)的硬件信息,如MAC地址
2、通过硬件信息生成一个机器码(算法1)
3、客户把机器码发给管理员
4、管理员由机器码生产key(算法2)
程序端的控制
1、首次使用,要求输入key
2、输入key后,与算法2生成的key做比较
(1)正确:将key写入到一个文件中
(2)不正确:输出错误信息
3、以后的使用中
在登录函数中加入验证程序,
验证程序的功能为由算法1,算法2生成key,与文件中的$ key做比较
本文所包含的代码举例 -
几道PHP算法题目
2007-11-15
1、给两个字符串s1,s2,定义字符串之间的距离d(s1,s2)为通过如下操作使两个字符
串一样的最少次数:
1.替换其中一个字符
2.删除一个字符
3.插入一个字符
例如:kooxoo.com与kooxoo.cn的距离为2,12344与1244的距离为1
给出任意两个字符串,求其距离,要求给出算法并分析时间复杂度
2、输入一个1~1亿的数字,打印中文,注意特殊情况
例如,输入7,打印七,123打印一百二十三
3、将一张考试卷的内容,看成一个文本文件,
题目形如: 1.1.。。。。。。。(3分)
(假设非空行最后字符均为空格)
要求实现检索出题号及其分值,并输出类似如下的:
1.1 3分
1.2 3分
1.3 5分
4、写算法和设计思想(越详细越好),并分析复杂度:
针对:输入框中输入字符,下面会动态匹配的那种功能
比如在搜索框中输入,上,会动态匹配:
上海 40000次搜索
商业 30000次搜索
酷讯的笔试题,暂时就这么多 -
prototype.js函数介绍
2007-6-02
基本用法:prototype.js给每个主要的类都分了一个Class,使用起来很方便.要产生特定的效果,只要用new Class.function(<argument>)就可以了.例如:函数名 解释 举例 Element.toggle 交替隐藏或显示 Element.toggle(''div1'',''div2'') Element.hide 隐藏 Element.hide(''div1'',''div2'') Element.show 显示 Element.show(''div1'',''div2'') Element.remove 删除 Element.remove(''div1'',''div2'') Element.getHeight 取得高度 Element.getHeight(''div1'') Toggle.display 和Element.toggle相同 Toggle.display(''div1'',''div2'') Insertion.Before 在DIV前插入文字 Insertion.Before(''div1'',''my content'') Insertion.After 在DIV后插入文字 Insertion.After(''div1'',''my content'') Insertion.Top 在DIV里最前插入文字 Insertion.Top(''div1'',''this is a text'') Insertion.Bottom 在DIV里最后插入文字 Insertion.Bottom(''div1'',''this is a text'') PeriodicalExecuter 以给定频率调用一段Javascrīpt PeridicalExecutor(test, 1)"这里test是Javascrīpt的函数,1是频率(1秒). $ 取得一个DIV, 相当于getElementById() $(''div1'') Field.clear 清空一个输入框 Field.clear(''textfield1'') Field.focus 把焦点集中在输入框上 Field.focus(''select1'') Field.present 判断内容是否为空 alert(Field.present(''textfield1''))" Field.select 选择输入框的内容 Field.select(''textfield1'')" Field.activate 把焦点集中在输入框上并选择输入框的内容 Field.activate(''textfield1'')" Form.serialize 把表格内容转化成string Form.getElements 取得表格内容为数组形式 Form.disable disable表格所有内容 Form.disable(''form1'') (这个好象不work) Form.focusFirstElement 把焦点集中在表格第一个元素上 Form.focusFirstElement(''form1'') Form.reset Reset表格 Form.reset(''form1'') Form.Element.getValue 取得表格输入框的值 Form.Element.getValue(''text1'') Form.Element.serialize 把表格中输入框内容转化成string Form.Element.serialize(''text1'') $F 等同于Form.Element.getValue() $F(''text1'') Effect.Highlight 高亮特效. Effect.Highlight(''text1'') Effect.Fade 褪色特效 Effect.Scale 放大缩小(百分比) Effect.Scale(''text1'', 200)
这里200 = 200%, 即两倍Effect.Squish 消失特效.文字缩小后消失 Effect.Squish(''text1'') Effect.Puff 消失特效.文字放大后消失 Effect.Puff(''text1'') Effect.Appear 出现特效 Effect.ContentZoom ZOOM特效. Ajax.Request 传送Ajax请求给服务器 Ajax.Request(''http://server/s.php'') Ajax.Updater 传送Ajax请求给服务器并用答复的结果更新指定的Container Ajax.Updater(''text1'',''http://server/s.php'') <DIV id="div1"><a href="#" ōnclick="new Element.toggle('div2')">Click Me</a></DIV>
<DIV id="div2">Hello!</DIV>当点击Click Me的时候,div2就会交替隐藏或显示.注意,你可以给toggle加上无限个parameter,比如Element.toggle(''div2'',''div3'',''div4'',...)
-
12条优化PHP的小提示
2007-6-02
1、If a method can be static, declare it static. Speed improvement is by a factor of 4.
1、如果一个函数可以声明为静态的,那么就用静态的,速度是改进的一个因素4.2、# Avoid magic like __get, __set, __autoload
2、避免使用__get, __set, __autoload等魔术函数3、require_once() is expensive
3、require_once()是相当昂贵的。4、Use full paths in includes and requires, less time spent on resolving the OS paths.
4、用include和require时,尽量用全路径,可以减少花在解决OS路径的时间5、If you need to find out the time when the scrīpt started executing, $_SERVER[’REQUEST_TIME’] is preferred to time()
5、如果你需要知道一个脚本的开始运行时间,用 $_SERVER[’REQUEST_TIME’]比用time()要好
6、See if you can use strncasecmp, strpbrk and stripos instead of regex
6、如果可以用strncasecmp, strpbrk and stripos就别用正则7、preg_replace is faster than str_replace, but strtr is faster than preg_replace by a factor of 4
7、preg_replace比str_replace要快,但是strtr比preg_replace更快8、If the function, such as string replacement function, accepts both arrays and single characters as arguments, and if your argument list is not too long, consider writing a few redundant replacement statements, passing one character at a time, instead of one line of code that accepts arrays as search and replace arguments.
一些函数,比如字符串替换函数,接受数组和单个字符做为参数,并且如果你的参数列表不是很长,考虑写一些冗余替换语句,每次传送一个字符,代替一行代码接受数组做为查找和替换的参数。9、Error suppression with @ is very slow.
9、禁止错误输出符号@是非常慢的。10、$row[’id’] is 7 times faster than $row[id]
10、、$row[’id’]比 $row[id]快7倍11、Error messages are expensive
11、错误信息是非常昂贵的12、Do not use functions inside of for loop, such as for ($x=0; $x < count($array); $x) The count() function gets called each time.
12、不要在循环内部使用函数,比如: for ($x=0; $x < count($array); $x)。count()函数在每次循环中都会被调用。对于模板,你是否在用smarty?这可能是保证把最经常访问的页面缓存起来的最快的方法了。
-
Web 2.0 Colour Palette
2007-5-26
Web 2.0 is about finding new ways to interact on the internet and collaboration, at least to a certain extent. Those of us in the know realise what Web2.0 is really all about - putting things on super shiney tables and painting them with gradients and candy colours and shiny silver and stuff.
Organised into 3 distinct colour groups - neutrals, muted tones and bold colours, you may recognize a few of the shades from some of your favourite Web2.0 sites. Now you can quickly and easily assemble your own colour scheme - simply choose any number of bold or muted colours, then add as many neutrals as you see fit - you'll have a Web2.0 masterpiece in no time at all!
Neutrals
Shiny silver [size=0.6em][#EEEEEE]
Reddit white [size=0.6em][#FFFFFF]
Magnolia Mag.nolia [size=0.6em][#F9F7ED]
Interactive action yellow [size=0.6em][#FFFF88]
Qoop Mint [size=0.6em][#CDEB8B]
Gmail blue [size=0.6em][#C3D9FF]
Shadows Grey [size=0.6em][#36393D]
Bold
Mozilla Red [size=0.6em][#FF1A00]
Rollyo Red [size=0.6em][#CC0000]
RSS Orange [size=0.6em][#FF7400]
Techcrunch green [size=0.6em][#008C00]
Newsvine Green [size=0.6em][#006E2E]
[float=right][/float]
Flock Blue [size=0.6em][#4096EE]
Flickr Pink [size=0.6em][#FF0084]
Muted
Ruby on Rails Red [size=0.6em][#B02B2C]
Etsy Vermillion [size=0.6em][#D15600]
43 Things Gold [size=0.6em][#C79810]
Writely Olive [size=0.6em][#73880A]
Basecamp Green [size=0.6em][#6BBA70]
Mozilla Blue [size=0.6em][#3F4C6B]
Digg Blue [size=0.6em][#356AA0]
Last.fm Crimson [size=0.6em][#D01F3C] -
Webdesign Resources网页设计资源
2007-5-26
收集了一些国外的资源..
Colors配色
- Iconico Colorpic
- Colourlovers
- 4096 Color Wheel
- Kuler by Adobe
- Colorblender
- Color Palette Generator
- Color Scheme Generator
- Colordb
- ColorWhore
- Accessibility Color Wheel
- Web 2.0 Colour Palette
- WellStyled
- colorjack.com
Images图片- Stock.xchng
- Morgue File
- Yotophoto
- ImageAfter
- StockVault
- BurningWell.org
- TextureKing
- PDPhoto
- Mayang’s Free Textures
- SquidFingers - Patterns
- Stripe Generator
Fonts字体- Dafont
- Urban Fonts
- Font Guide for Webmasters
- Typetester
- TrulyFreeStock.com
- Font Type Navigator
- Search Free Fonts
- Mark Boulton
- GoodFonts.org
- Fontleech
Icons图标
HTML- Special Characters
- HTML Character Entities
- Special Characters in HTML
- HTML Help
- XHTML Overview
- A Guide to XHTML 1.1
- Doctor HTML
Validation
[ 本帖最后由 04007147 于 2007-5-26 19:54 编辑 ] -
使用php的几个小技巧zz
2007-5-26
php的一些小技巧
1. str_replace
str_replace是非常常常常常用的php函数,用于字符串替换,经常看到某些php新人为了替换一批字符串,写了好多行str_replace,实在是惨不忍睹。
比如这个例子:
PHP:-
$str = '某人的栖息地 --- www.ooso.net';
-
$str = str_replace('某人', '坏人', $str);
-
$str = str_replace('的', 'di', $str);
-
$str = str_replace('栖息地', '猪窝窝', $str);
-
$str = str_replace('www.ooso.net', 'ooso.net', $str);
以上,替换了4次字符串,实际只要换个写法,一行就搞定了:
PHP:-
$str = '某人的栖息地 --- www.ooso.net';
-
$str = str_replace(array('某人', '的', '栖息地', 'www.ooso.net'), array('坏人', 'di', '猪窝窝', 'ooso.net'), $str);
2. array
经常看到有人拿数组这样写:
echo $arr[some_key];上面这行代码能跑,看上去也没什么大问题,但是如果你把php.ini的error notice打开的话,会收到一大批error。php解析器首先是拿“some_key”当作一个常量来解释的,但如果没有定义some_key这样一个常量,解析器还是很宽容的把它当作了一个字符串来看待。因此新人同学们最好写完整一点:
echo $arr['some_key'];这样就没有问题了,如果你要把它放在双引号中连用,也不能省掉引号,可以这样写:
echo "这是混在双引号中的字符串{$arr['some_key']}";3. 类型戏法
类型戏法相当好用,比如有一个表单提交过来的变量,正常情况下它应该是整型的,有时候偷懒省去校验的写法可以是这样的:
$intVar = (int)$_POST['post_var'];再比如数组,有时候写键值要打引号是不是很不爽啊,我们可以把它转换成object,比如:
$arr = array('name' => 'volcano', 'sex' => 'male');-
$arr = (object)$arr;
-
-
echo $arr->name;
-
echo $arr->sex;
是不是很省事?
4. lambda函数
lamda函数和array_*系列函数使用有奇效,拿php手册上的一个例子来说:
-
<?php
-
$av = array("the ", "a ", "that ", "this ");
-
array_walk($av, create_function('&$v,$k', '$v = $v . "mango";'));
-
print_r($av);
-
?>
至少省了一个for循环
5. 嵌套循环显示表格的单元格
嵌套循环显示表格的单元格,这是一个很老的话题哦,往往会要在某个单元格后边加个条件判断什么的,考虑是不是要输出tr抑或是td标签。
俺这里介绍一个办法,利用array_chunk函数能够比较工整的输出html,见下例,这个例子要输出一个4行6列的表格:
<?php-
$arr = range(1, 24); //这个会生成一个数组array(1,2,3,4....24)
-
$arr = array_chunk($arr, 6);
-
-
// output table
-
?>
-
-
<table>
-
<?php foreach($arr as $row): ?>
-
<tr>
-
<?php foreach($row as $col):?>
-
<td><?php echo $col?></td>
-
<?php endforeach;?>
-
</tr>
-
<?php endforeach;?>
-
</table>
-
-
PHP中的实用函数
2007-5-24
1、关于PHP重定向
2、获取访问者浏览器方法一:header("Location: index.php");
方法二:echo "<scrīpt>window.location ="$PHP_SELF";</scrīpt>";
方法三:echo "<META HTTP-EQUIV="Refresh" CONTENT="0; URL=index.php">";CODE:function browse_infor()
{
$browser="";$browserver="";
$Browsers =array("Lynx","MOSAIC","AOL","Opera","JAVA","MacWeb","WebExplorer","OmniWeb");
$Agent = $GLOBALS["HTTP_USER_AGENT"];
for ($i=0; $i<=7; $i++)
{
if (strpos($Agent,$Browsers[$i]))
{
$browser = $Browsers[$i];
$browserver ="";
}
}
if (ereg("Mozilla",$Agent) && !ereg("MSIE",$Agent))
{
$temp =explode("(", $Agent); $Part=$temp[0];
$temp =explode("/", $Part); $browserver=$temp[1];
$temp =explode(" ",$browserver); $browserver=$temp[0];
$browserver =preg_replace("/([d.]+)/","1",$browserver);
$browserver = " $browserver";
$browser = "Netscape Navigator";
}
if (ereg("Mozilla",$Agent) && ereg("Opera",$Agent))
{
$temp =explode("(", $Agent); $Part=$temp[1];
$temp =explode(")", $Part); $browserver=$temp[1];
$temp =explode(" ",$browserver);$browserver=$temp[2];
$browserver =preg_replace("/([d.]+)/","1",$browserver);
$browserver = " $browserver";
$browser = "Opera";
}
if (ereg("Mozilla",$Agent) && ereg("MSIE",$Agent))
{
$temp = explode("(", $Agent); $Part=$temp[1];
$temp = explode(";",$Part); $Part=$temp[1];
$temp = explode(" ",$Part);$browserver=$temp[2];
$browserver =preg_replace("/([d.]+)/","1",$browserver);
$browserver = " $browserver";
$browser = "Internet Explorer";
}
if ($browser!="")
{
$browseinfo = "$browser$browserver";
}
else
{
$browseinfo = "Unknown";
}
return $browseinfo;
}
//调用方法$browser=browseinfo() ;直接返回结果
3、获取访问者操作系统
CODE:function osinfo() {
$os="";
$Agent = $GLOBALS["HTTP_USER_AGENT"];
if (eregi('win',$Agent) && strpos($Agent, '95')) {
$os="Windows 95";
}
elseif (eregi('win 9x',$Agent) && strpos($Agent, '4.90')) {
$os="Windows ME";
}
elseif (eregi('win',$Agent) && ereg('98',$Agent)) {
$os="Windows 98";
}
elseif (eregi('win',$Agent) && eregi('nt 5.0',$Agent)) {
$os="Windows 2000";
}
elseif (eregi('win',$Agent) && eregi('nt',$Agent)) {
$os="Windows NT";
}
elseif (eregi('win',$Agent) && eregi('nt 5.1',$Agent)) {
$os="Windows XP";
}
elseif (eregi('win',$Agent) && ereg('32',$Agent)) {
$os="Windows 32";
}
elseif (eregi('linux',$Agent)) {
$os="Linux";
}
elseif (eregi('unix',$Agent)) {
$os="Unix";
}
elseif (eregi('sun',$Agent) && eregi('os',$Agent)) {
$os="SunOS";
}
elseif (eregi('ibm',$Agent) && eregi('os',$Agent)) {
$os="IBM OS/2";
}
elseif (eregi('Mac',$Agent) && eregi('PC',$Agent)) {
$os="Macintosh";
}
elseif (eregi('PowerPC',$Agent)) {
$os="PowerPC";
}
elseif (eregi('AIX',$Agent)) {
$os="AIX";
}
elseif (eregi('HPUX',$Agent)) {
$os="HPUX";
}
elseif (eregi('NetBSD',$Agent)) {
$os="NetBSD";
}
elseif (eregi('BSD',$Agent)) {
$os="BSD";
}
elseif (ereg('OSF1',$Agent)) {
$os="OSF1";
}
elseif (ereg('IRIX',$Agent)) {
$os="IRIX";
}
elseif (eregi('FreeBSD',$Agent)) {
$os="FreeBSD";
}
if ($os=='') $os = "Unknown";
return $os;
}
//调用方法$os=os_infor() ;
4、文件格式类
CODE:$mime_types = array(
'gif' => 'image/gif',
'jpg' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'jpe' => 'image/jpeg',
'bmp' => 'image/bmp',
'png' => 'image/png',
'tif' => 'image/tiff',
'tiff' => 'image/tiff',
'pict' => 'image/x-pict',
'pic' => 'image/x-pict',
'pct' => 'image/x-pict',
'tif' => 'image/tiff',
'tiff' => 'image/tiff',
'psd' => 'image/x-photoshop',
'swf' => 'application/x-shockwave-flash',
'js' => 'application/x-javascrīpt',
'pdf' => 'application/pdf',
'ps' => 'application/postscrīpt',
'eps' => 'application/postscrīpt',
'ai' => 'application/postscrīpt',
'wmf' => 'application/x-msmetafile',
'css' => 'text/css',
'htm' => 'text/html',
'html' => 'text/html',
'txt' => 'text/plain',
'xml' => 'text/xml',
'wml' => 'text/wml',
'wbmp' => 'image/vnd.wap.wbmp',
'mid' => 'audio/midi',
'wav' => 'audio/wav',
'mp3' => 'audio/mpeg',
'mp2' => 'audio/mpeg',
'avi' => 'video/x-msvideo',
'mpeg' => 'video/mpeg',
'mpg' => 'video/mpeg',
'qt' => 'video/quicktime',
'mov' => 'video/quicktime',
'lha' => 'application/x-lha',
'lzh' => 'application/x-lha',
'z' => 'application/x-compress',
'gtar' => 'application/x-gtar',
'gz' => 'application/x-gzip',
'gzip' => 'application/x-gzip',
'tgz' => 'application/x-gzip',
'tar' => 'application/x-tar',
'bz2' => 'application/bzip2',
'zip' => 'application/zip',
'arj' => 'application/x-arj',
'rar' => 'application/x-rar-compressed',
'hqx' => 'application/mac-binhex40',
'sit' => 'application/x-stuffit',
'bin' => 'application/x-macbinary',
'uu' => 'text/x-uuencode',
'uue' => 'text/x-uuencode',
'latex'=> 'application/x-latex',
'ltx' => 'application/x-latex',
'tcl' => 'application/x-tcl',
'pgp' => 'application/pgp',
'asc' => 'application/pgp',
'exe' => 'application/x-msdownload',
'doc' => 'application/msword',
'rtf' => 'application/rtf',
'xls' => 'application/vnd.ms-excel',
'ppt' => 'application/vnd.ms-powerpoint',
'mdb' => 'application/x-msaccess',
'wri' => 'application/x-mswrite',
);
5、php生成excel文档CODE:<?
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=test.xls");
echo "test1t";
echo "test2tn";
echo "test1t";
echo "test2tn";
echo "test1t";
echo "test2tn";
echo "test1t";
echo "test2tn";
echo "test1t";
echo "test2tn";
echo "test1t";
echo "test2tn";
?>
//改动相应文件头就可以输出.doc .xls等文件格式了
6、时间比较问题
举一个简单例子说明:比如一个论坛对当天发表的贴子用new图片标记一下。
方法一:
CODE://$db->rows[$i][date]中为数据库中datetime字段值.
$today=time();
$theDay=date("Y-m-d H:i:s",$today-24*3600);
$newTag=$db->rows[$i][date]>=$theDay?"<img src='../image/newinfor.gif'>":"";
方法二:
CODE:$newTag=$db->rows[$i][date]>=date("Y-m-d 00:00:00")?"<img src='../image/newinfor.gif'>":"";
//提取页面和浏览器提交的变量,作用相当于使PHP.INI开了全局变量
CODE:@extract($_SERVER, EXTR_SKIP);
@extract($_SESSION, EXTR_SKIP);
@extract($_POST, EXTR_SKIP);
@extract($_FILES, EXTR_SKIP);
@extract($_GET, EXTR_SKIP);
@extract($_ENV, EXTR_SKIP);
//得到ip地址
CODE:$ip=$_SERVER['REMOTE_ADDR'];
$ip1 = getenv('HTTP_X_FORWARDED_FOR');
if (($ip1 != "") && ($ip1 != "unknown")) $ip=$ip1;
//读取文件函数
CODE:function readfromfile($file_name) {
if (file_exists($file_name)) {
$filenum=fopen($file_name,"r");
flock($filenum,LOCK_EX);
$file_data=fread($filenum, filesize($file_name));
rewind($filenum);
fclose($filenum);
return $file_data;
}
}
//写入文件函数
CODE:function writetofile($file_name,$data,$method="w") {
$filenum=fopen($file_name,$method);
flock($filenum,LOCK_EX);
$file_data=fwrite($filenum,$data);
fclose($filenum);
return $file_data;
}
//页面快速转向
CODE:function turntopage($url="index.php",$info = "页面转向中...",$second=2){
print "<html>n<head>n<title>页面转向中....</title>n";
print "<meta http-equiv="refresh" content="$second;url=$url">n";
print "<style type="text/css">n<!--n";
print "td { font-family: "Verdana", "Arial";font-size: 12px}n";
print "A {COLOR: #000000; TEXT-DECORATION: none}n";
print "-->n</style>n";
print "</head>n<body>n";
print "<table width="100%" border="0" align="center">n";
print " <tr>n";
print " <td height="200"> </td>n";
print " </tr>n";
print " <tr>n";
print " <td align="center">n";
print " <table width="60%" border="0" cellpadding="8" bgcolor="#AA9FFF">n";
print " <tr>n";
print " <td height="30" align="center">页面转向提示信息</td>n";
print " </tr>n";
print " <tr>n";
print " <td align="center">$info</td>n";
print " </tr>n";
print " <tr>n";
print " <td align="center">n";
print " <a href="$url">如果你的浏览器不支持自动跳转,请按这里</a></td>n";
print " </tr>n";
print " </table></td>n";
print " </tr>n";
print " <tr>n";
print " <td height="200"> </td>n";
print " </tr>n";
print "</table>n";
print "</body>n</html>";
exit;


