<? php // 学习小结[案例]//上一页/下一页链接//标题字符乱码 []后加---//文本不能换行 [style="word-break:break-all;word-wrap:break-word;"]//两模板名称统一 //网站没有即时更新的去除(缓存) 己作处理//链接不能出错 //对存入数据库时,进行验证处理//图片大小存在问题及是否存在问题(解决中)//音乐更新问题(写入缓存己改)[前台后台]//下载之前请先备份//<%%>外面不能留空行//jsonrpc, dwr, buffalo, prototype//技术小结//常量定义 define ( ' NL ' , " " ); // 乱码 < meta http - equiv = " content-type " content = " text/xml; charset=gb2312 " /> __LINE__ // 文件中的当前行号。 __FILE__ // 文件的完整路径和文件名。如果用在包含文件中,则返回包含文件名。自 PHP 4.0.2 起,总是包含一个绝对路径,而在此之前的版本有时会包含一个相对路径。 __FUNCTION__ // 函数名称(PHP 4.3.0 新加)。自 PHP 5 起本常量返回该函数被定义时的名字(区分大小写)。在 PHP 4 中该值总是小写字母的。 __CLASS__ // 类的名称(PHP 4.3.0 新加)。自 PHP 5 起本常量返回该类被定义时的名字(区分大小写)。在 PHP 4 中该值总是小写字母的。 __METHOD__ // 类的方法名(PHP 5.0.0 新加)。返回该方法被定义时的名字(区分大小写)。 //数组操作 in_array ( $rs -> fields[ ' id ' ] , $url_category_ary ) array_push ( $url_category_ary , $result [ ' id ' ]) // array_keys ($array, "blue"));//array_keys() 返回 input 数组中的数字或者字符串的键名。 $data = array ( ' foo ' => ' bar ' , ' baz ' => ' boom ' , ' cow ' => ' milk ' , ' php ' => ' hypertext processor ' ); echo http_build_query ( $data ); ///* 输出: foo=bar&baz=boom&cow=milk&php=hypertext+processor */ array_key_exists ( $USER_INFO_ARY [ " user_province " ] , $PROVINCE_ARY ) // 键是否在数组中 $ary = array_flip ( $star_name ); // 将键/值反转 array_unique ( $photo_uid_ary ); // 从数组中取出唯一值//判断处理技巧 isset ( $id ) && is_numeric ( $id ) && $id > 0 isset ( $id ) && is_array ( $id ) && count ( $id ) > 0 // preg_match preg_match ( " /(^[a-z]{1})([a-z0-9_]{2,15}$)/ " , $admin_name ) preg_match ( ' #^http[s]?/:[a-z0-9-]+.([a-z0-9-]+.)?[a-z]+#i ' , $blog_url ) preg_match ( " /^[a-z0-9&'.-_+]+@[a-z0-9-]+.([a-z0-9-]+.)*?[a-z]+$/is " , $user_email ) echo floor ( 4.3 ); // 4 echo ceil ( 4.3 ); // 5 echo ceil ( 9.999 ); // 10 echo round ( 3.6 ); // 4 echo $_SERVER [ ' HTTP_REFERER ' ]; // <input disabled title='只有VIP才拥有此功能!' type=radio name=bg_radio value=userbg/006.gif >// get host name from URL preg_match ( " /^(http://)?([^/]+)/i " , " http://www.php.net/index.html " , $matches ); $host = $matches [ 2 ]; // get last two segments of host name preg_match ( " /[^./]+.[^./]+$/ " , $host , $matches ); echo " domain name is: " . $matches [ 0 ] . " " ; // get host name from URL preg_match ( " /^(http://)?([^/]+)/i " , " http://www.php.net/index.html " , $matches ); $host = $matches [ 2 ]; // get last two segments of host name preg_match ( " /[^./]+.[^./]+$/ " , $host , $matches ); echo " domain name is: " . $matches [ 0 ] . " " ; // preg_match ( " /^(19|20)[0-9]{2}$/ " , $birth_year // write file @ $fp = fopen ( " $DOCUMENT_ROOT/../orders/orders.txt " , ' ab ' ); flock ( $fp , LOCK_EX); if ( ! $fp ){ echo ' <p><strong> Your order could not be processed at this time. ' . ' Please try again later.</strong></p></body></html> ' ; exit ;} fwrite ( $fp , $outputstring , strlen ( $outputstring )); flock ( $fp , LOCK_UN); fclose ( $fp ); // $outputstring = $date . " " . $tireqty . " tires " . $oilqty . " oil " . $sparkqty . " spark plugs $ " . $totalamount . " " . $address . " " ; // $DOCUMENT_ROOT = $_SERVER [ ' DOCUMENT_ROOT ' ];@ $fp = fopen ( " $DOCUMENT_ROOT/../orders/orders.txt " , ' rb ' ); if ( ! $fp ) { echo ' <p><strong>No orders pending. ' . ' Please try again later.</strong></p> ' ; exit ; } while ( ! feof ( $fp )) { $order = fgets ( $fp , 999 ); echo $order . ' <br /> ' ; } echo ' Final position of the file pointer is ' . ( ftell ( $fp )); echo ' <br /> ' ; rewind ( $fp ); echo ' After rewind, the position is ' . ( ftell ( $fp )); echo ' <br /> ' ; fclose ( $fp ); // 验证非法字符 name传进的字符传 function validchars(str){ var str_match = " ^&*;'‘ " ; for (i = 0 ;i < str . length;i ++ ) { if (str_match . indexOf(str . charAt(i)) !=- 1 ){ // indexOf 方法返回一个整数值,指出 String 对象内子字符串的开始位置。如果没有找到子字符串,则返回 -1 return true ; } }} // 组合成数组 $url_category_ary = explode ( ' , ' , $url_category ) // 以,组合成数组 implode ( ' , ' , $url_category_ary ) // 设置cookie setcookie ( ' url_category ' , $vars , time () + 1200 ); $_POST [ $url_category ] $_GET [ $url_category ] $_COOKIE [ $url_category ] $_SESSION [ $url_category ] $_FILES [ $url_category ]$ $url_category = $_GET [ $url_category ]; // $_SERVER [ ' PHP_SELF ' ] $_SERVER [ ' HTTP_REFERER ' ] /* “REMOTE_HOST”正在浏览当前页面用户的主机名。反向域名解析基于该用户的 REMOTE_ADDR。 “REMOTE_ADDR”正在浏览当前页面用户的 IP 地址。 “DOCUMENT_ROOT”当前运行脚本所在的文档根目录。在服务器配置文件中定义。“HTTP_REFERER”链接到当前页面的前一页面的 URL 地址。不是所有的用户代理(浏览器)都会设置这个变量,而且有的还可以手工修改 HTTP_REFERER。因此,这个变量不总是真实正确的。 “SERVER_NAME”当前运行脚本所在服务器主机的名称。如果该脚本运行在一个虚拟主机上,该名称是由那个虚拟主机所设置的值决定。 “PHP_SELF”当前正在执行脚本的文件名,与 document root 相关。举例来说,在 URL 地址为 http://example.com/test.php/foo.bar 的脚本中使用 $_SERVER['PHP_SELF'] 将会得到 /test.php/foo.bar 这个结果。__FILE__ 常量包含当前(例如包含)文件的绝对路径和文件名。 */ // adodb学习小结 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; $rs1 = $db -> Execute( ' select * from table ' ); $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; $rs2 = $db -> Execute( ' select * from table ' ); print_r ( $rs1 -> fields); # shows array([0]=>'v0',[1] =>'v1') print_r ( $rs2 -> fields); # shows array(['col1']=>'v0',['col2'] =>'v1')// if ( ! $rs = $db -> Execute( $sql )) { echo $db -> ErrorMsg(); $db -> Close(); exit ( ' <a href="/">数据库错误,请访问其它页面</a> ' );} // $db -> ErrorMsg(); $recordSet -> Close(); # optional $db -> Close(); # optional if ( $conn -> Execute( $sql ) === false ) { print ' error inserting: ' . $conn -> ErrorMsg() . ' <BR> ' ;} // 设为首面/加入收藏开夹 /* <span style="CURSOR: hand" onClick="window.external.addFavorite('url','MSHOW导航栏')">收藏[我的导航]</span> <a style="cursor:hand" οnclick="this.style.behavior='url(#default#homepage)';this.setHomePage('url');">设为首页</a> */ // 换行用 //所有的祸与福皆从口出,所以事事必谨言慎行,切记//遍历循环 foreach ( $PROVINCE_ARY as $province_id => $province_name ) {} // javascript学习小结//form.email.focus(); 表单获得焦点//form.password.value.length 表单域宽度//exec 方法用正则表达式模式在字符串中运行查找,并返回包含该查找结果的一个数组。rgExp.exec(str)参数rgExp必选项。包含正则表达式模式和可用标志的正则表达式对象。str必选项。要在其中执行查找的 String 对象或字符串文字。 var patrn =/ (swf | gif | jpg | png) / ; if ( ! patrn . exec (upload_file . toLowerCase())) { alert( " 格式不正确! " ); return false ; } // 验证用户名 function isUserName(s) { var patrn =/^ [a - z]{ 1 }[a - z0 - 9_]{ 2 , 15 }$ / ; // a-Z为1位 2-15位为a-z 0-9 if ( ! patrn . exec (s)) return false ; // exec 方法用正则表达式模式在字符串中运行查找,并返回包含该查找结果的一个数组。 return true ;} // 获得网页中一些图片属性 function changeImageWidth(w) { for (num = 0 ;num < document . images . length;num ++ ) { if (document . images[num] . width > w && document . images[num] . alt . indexOf( ' keep_width ' ) == - 1 ) { document . images[num] . width = w; document . images[num] . alt = ' 点击图片可以查看大图 ' ; document . images[num] . onclick = function () {window . open( '' + this . src + '' );} document . images[num] . style . cursor = " hand " ; document . images[num] . border = 1 ; } } setTimeout( " changeImageWidth( " + w + " ) " , 5000 );} // use method [<IMG SRC="url" οnlοad="resizepic(this,450,999)" border=0>] function resizepic(thepic , w , h){ var intImageWidth = thepic . width; var intImageHeight = thepic . height; if (intImageWidth > w || intImageHeight > h) { if (intImageWidth / intImageHeight > w / h ) { thepic . width = w; thepic . height = intImageHeight * w / intImageWidth } else { thepic . height = h; thepic . width = intImageWidth * h / intImageHeight } thepic . alt = " 按此在新窗口浏览图片 " ; thepic . onclick = function (){window . open(this . src)} }} // open new window function OpenWin( gourl , w , h , l , t , win){ // [in] gourl: 弹出窗口的url // [in] w: 弹出窗口的宽度 // [in] h: 弹出窗口的高度 // [in] l: 弹出窗口初始位置(screen left) // [in] t: 弹出窗口初始位置(screen top)// var m_left = ( screen.width - w ) / 2;// var m_top = ( screen.height - h ) / 2; var m_left = 10 ; var m_top = 10 ; if ( l != null && l != '' )m_left = m_left + l / 2 ; if ( t != null && t != '' )m_top = m_top + t / 2 ; if ( win == null || win == '' )win = '' ; w += 20 ; param = ' resizable=1, scrollbars=1, width= ' + w + ' , height= ' + h + ' , left= ' + m_left + ' ; top= ' + m_top; window . open ( gourl , win , param ); try {window . event . returnValue = false ;} catch (E){}} // innerHTMLouterHTMLinnerHTML 与innerHTML不同,outerHTML包括整个标签,而不仅限于标签内部的内容。对于一个id为 " testdiv " 的div来说,outerHTML、innerHTML以及innerTEXT // javascript 获得name的cookie值 BLOG_USERNAME = GetCookie( " BLOG_USERNAME " ); < script language = " javascript " > function chageDiv(){ document . getElementById( " div1 " ) . innerHTML = " 值为1 " ;} </ script > DIV块测试: < div id = " div1 " > 默认值 </ div > < a href = " # " onClick = " chageDiv() " > 改变值为1 </ a > # ######################## document . getElementById( " select_bg " ) . innerHTML = document . getElementById( " system_skin2 " ) . innerHTML;document . getElementById( " select_bg " ) . style . display = '' ; < div id = " select_bg " >& nbsp; < div > < span id = " system_skin2 " style = " display:none " > 代码显示区域 </ span > // 得到cookie function getCookie( Key ){ var search = Key + " = " ; begin = document . cookie . indexOf(search); if (begin != - 1 ) { begin += search . length; end = document . cookie . indexOf( " ; " , begin); if ( end == - 1 ) end = document . cookie . length; return document . cookie . substring(begin , end ); }} // < script > var article = new Array ( Array ( 1 , ' 心情故事 ' ) , Array ( 2 , ' 随想录 ' ) , Array ( 3 , ' 转载 ' )); function show_category(){ document . write( " <select name='category'></select> " ); var selectTag = category; selectTag . options . length = 0 ; for (i = 0 ;i < article . length;i ++ ){ selectTag . options . add( new Option(article[i][ 1 ] , article[i][ 0 ])); }}show_category(); </ script > // 图层设置透明度 < DIV id = aaa style = " Z-INDEX: 1; LEFT: 0px; POSITION: absolute;FILTER: alpha(opacity=<{$DIAPHANEITY}>); TOP: 0px " > /* 字符串连接 var today = new Date(); var year = today.getFullYear(); var month = today.getMonth()+1; var mday = today.getDate(); var todayValue = year + "-" + month + "-" + mday;数组的定义(后不加,)province_ary = new Array(Array("1","北京"),Array("30","台湾")); */ // ~!@#$%^&*()_+}{":?><`-=][;'/.,|//DATE_FORMA (date, format) 根据格式串format //SELECT DATE_FORMAT(date, '%Y-%c-%e') AS wdate FROM user_diary WHERE uid= '90453' GROUP BY DATE_FORMAT(wdate, '%Y-%c-%e') /* DATE_FORMAT(wdate, '%Y-%m-%d') 格式化日期或日期和时间值date,返回结果串。可用DATE_FORMAT( ) 来格式化DATE 或DATETIME 值,以便得到所希望的格式。根据format字符串格式化date值:%S, %s 两位数字形式的秒( 00,01, . . ., 59)%i 两位数字形式的分( 00,01, . . ., 59)%H 两位数字形式的小时,24 小时(00,01, . . ., 23)%h, %I 两位数字形式的小时,12 小时(01,02, . . ., 12)%k 数字形式的小时,24 小时(0,1, . . ., 23)%l 数字形式的小时,12 小时(1, 2, . . ., 12)%T 24 小时的时间形式(h h : m m : s s)%r 12 小时的时间形式(hh:mm:ss AM 或hh:mm:ss PM)%p AM 或P M%W 一周中每一天的名称( S u n d a y, Monday, . . ., Saturday)%a 一周中每一天名称的缩写( Sun, Mon, . . ., Sat)%d 两位数字表示月中的天数( 00, 01, . . ., 31)##########%e 数字形式表示月中的天数( 1, 2, . . ., 31) ##########%D 英文后缀表示月中的天数( 1st, 2nd, 3rd, . . .)%w 以数字形式表示周中的天数( 0 = S u n d a y, 1=Monday, . . ., 6=Saturday)%j 以三位数字表示年中的天数( 001, 002, . . ., 366)% U 周(0, 1, 52),其中Sunday 为周中的第一天 ##########%u 周(0, 1, 52),其中Monday 为周中的第一天 ##########%M 月名(J a n u a r y, February, . . ., December)%b 缩写的月名( J a n u a r y, February, . . ., December)%m 两位数字表示的月份( 01, 02, . . ., 12)%c 数字表示的月份( 1, 2, . . ., 12)%Y 四位数字表示的年份%y 两位数字表示的年份%% 直接值“%” */ // 正则表达式 学习小结//正则表达式“t[aeio]n”只匹配“tan”、“Ten”、“tin”和“ton”。//“t(a|e|i|o|oo)n”正则表达式。这里不能使用方扩号,因为方括号只允许匹配单个字符;这里必须使用圆括号“()”。 tan ten tin ton toon//符号 * 0次或n次 + 0次或n次 ? 0次或1次 {n}恰好N次{n,m} n次到m次//“^”符号称为“否”符号。如果用在方括号内,“^”表示不想要匹配的字符。例如,[^x]的正则表达式匹配所有单词,但以“X”字母开头的单词除外 //[a-z]+后继字母,可能a-z的任意字母//month dd,yyyy [a-z]+s [0-9]{1,2},s* [0-9]{4}新出现的“s”符号是空白符号,匹配所有的空白字符,包括Tab字符。//正则表达式的开始符:^,结尾符$,这两个符号间的是匹配的元素。如检查一个电话号码是不是打往北京的号,用正则表达式表示就是“^010$”。只要前3位区号是010//^ 断言目标的开头(或在多行模式下行的开头,即紧随一换行符之后) //$ 断言目标的结尾(或在多行模式下行的结尾,即紧随一换行符之前) //.匹配除了换行符外的任意一个字符(默认情况下) //[字符类定义开始 ]字符类定义结束 //|开始一个多选一的分支 //(子模式开始 )子模式结束 //?扩展 ( 的含义,也是 0 或 1 数量限定符,以及数量限定符最小值 //*匹配 0 个或多个的数量限定符 //+匹配 1 个或多个的数量限定符 //{最少/最多数量限定开始 //}最少/最多数量限定结束 /* PHP有六个函数来处理正则表达式,它们都把一个正则表达式作为它们的第一个参数,列出如下:ereg: 最常用的正则表达式函数, ereg 允许我们搜索跟一个正则表达式匹配的一个字符串.$date = "2005-6-7";if (ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $date, $regs)) { echo "$regs[3].$regs[2].$regs[1]";} ereg_replace: 允许我们搜索跟正则表达式匹配的一个字符串,并用新的字符串代替所有这个表达式出现的地方。$string = "This is a test";echo str_replace(" is", " was", $string);echo ereg_replace("( )is", "/1was", $string);echo ereg_replace("(( )is)", "/2was", $string);$num = '4';$string = "This string has four words.";$string = ereg_replace('four', $num, $string);echo $string; //Output: 'This string has 4 words.'eregi: 和ereg几乎是一样效果,不过忽略大小写。 eregi_replace: 和ereg_replace有着一样的搜索-替换功能,不过忽略大小写. split: 允许我们搜索和正则表达式匹配的字符串,并且以字符串集合的方式返回匹配结果. spliti: split函数忽略大小写的版本.$date = "04/30/1973";list($month, $day, $year) = split ('[/.-]', $date);echo "Month: $month; Day: $day; Year: $year<br /> "; */ $str = ' hypertext language programming ' ; $chars = preg_split ( ' / / ' , $str ); print_r ( $chars ); preg_match_all ( " /(<([w]+)[^>]*>)(.*)(<//2>)/ " , $html_str , $matches ); // 索目标中所有匹配,然后按照指定顺序放到结果数组中. 如果找到第一个匹配,则后续的匹配从上一个匹配结尾处开始搜 ?> < form enctype = " multipart/form-data " method = " post " > <? php for ( $i = 0 ; $i < 10 ; $i ++ ){ ?> < input type = " file " name = " file[] " > <? php } ?> < input type = " submit " value = " dsa " > </ form > <? php $f = $HTTP_POST_FILES [ ' file ' ]; if ( $f ){ for ( $i = 0 ; $i < 10 ; $i ++ ){ $dest = ' uploads/ ' . date (ymd) . $f [ ' name ' ][ $i ]; // 我这里设置文件名为日期加上文件名避免重复 $r = move_uploaded_file ( $f [ ' tmp_name ' ][ $i ] , $dest ); echo $f [ ' name ' ][ $i ] . " <br><img src='$dest' height=20 width=20> " ;} } ?> <? php @ header ( " Content-Type: text/html; charset=gb2312 " ); // while循环 while ( list ( $var_name , $null ) = @ each ( $var )) { unset ( $GLOBALS [ $var_name ]); } ?> <? php // get 外部网址 $_SERVER [ " HTTP_REFERER " ] // $_SERVER [ " SERVER_NAME " ] // localhost //设置透明度 td table style="FILTER: alpha(opacity=100)"//删除之前提醒客户 < A href = " javascript:if(confirm('确定要删除这条留言吗?'))location='url' " > [删除] </ A > < a href = " # " onclick = " alert('ddddd'); " ></ a > /* οnlοad="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7;this.alt='点击在新窗口查看全图 CTRL+鼠标滚轮放大或缩小';}" οnmοuseοver="if(this.resized) this.style.cursor='hand';" οnclick="if(!this.resized) {return false;} else {window.open('url');}" onmousewheel="return imgzoom(this);" */ // adodb 对字段的魔术处理 $db->qstr($field, $magic_quotes)//从静态网页截取字符串函数 注意:$first_str, $last_str 唯一 $content_str = file_get_contents ( $url ); // function cut( $first_str , $last_str ){ // $first_str 起始字符串 $last 结束字符串 global $content_str ; // 待截取内容 $message = explode ( $first_str , $content_str ); // 以 $first_str 为限,返回数组 $message = explode ( $last_str , $message [ 1 ]); // 再次截取 return $message [ 0 ];} /* $sql= "SELECT * FROM `star_info` ";$rs = $db->SelectLimit($sql,5);while(!$rs->EOF){ echo $rs->fields['star_class'].'<br>'; $rs->MoveNext();} */ // list & array " fruits " => array ( " a " => " orange " , " c " => " apple " ) , // 返回根据参数建立的数组。参数可以用 => 运算符给出索引。 $info = array ( ' coffee ' , ' brown ' , ' caffeine ' ); // list() 用一步操作给一组变量进行赋值 list ( $drink , $color , $power ) = $info ; // 把数组中的值赋给一些变量//统计页面执行时间 function getmicrotime(){ list ( $usec , $sec ) = explode ( " " , microtime ()); return (( float ) $usec + ( float ) $sec );} $start_time = getmicrotime(); $end_time = getmicrotime(); $time = $end_time - $start_time ; // 从数组中随机选一个参数 $price_ary [ $i ] = $i ; $price = array_rand ( $price_ary ); // 拷贝到本服务器 bool copy ( string source, string dest ) 将文件从 source 拷贝到 dest。如果成功则返回 TRUE,失败则返回 FALSE。 copy ( $source , $dest ) // i.g. copy('http://astro.sina.com.cn/1.html','2.html') date ( " Ynj " , filemtime ( ' 抓取的到本地文件 ' )) == date ( " Ynj " ) // 防止重复抓取当天文件//常用循环格式 while ( list ( $subscript , $value ) = each ( $data )) { echo " $subscript => $value :: " ; } reset ( $data ); foreach ( $data as $subscript => $value ) { echo " $subscript => $value :: " ; } // unset() 销毁指定的变量//生成函数 function get_html( $body , $filename ){ $fp = fopen ( $filename , " w " ); if ( fwrite ( $fp , $body ) == true ){ $result = true ; } else { $result = false ; } fclose ( $fp ); chmod ( $filename , 0777 ); // mode 参数指定了访问限制 return $result ;} // smarty模板总结//=======模板设置============== require_once ( ' Smarty.class.php ' ); class SmartyTemplate extends Smarty { global $path_root ; function SmartyTemplate() { $this -> compile_check = true ; // 编译检查变量 $this -> debugging = true ; // 默认为当目录 $this -> template_dir = $path_root . " template/templates " ; // 设置模板目录 $this -> compile_dir = $path_root . " template/templates_c " ; // 设置编译目录 $this -> config_dir = $path_root ; // 设置配置目录 $this -> cache_dir = $path_root ; // 设置缓存目录 if ( trim ( $template_name ) != '' && ! file_exists ( $this -> compile_dir)) { umask ( 011 ); mkdir ( $this -> compile_dir , 0700 ); } $this -> left_delimiter = " <{ " ; $this -> right_delimiter = " }> " ; }} $tpl = new SmartyTemplate(); $tpl -> assign( $star_info = array ( ' istar ' => $istar . " 运程 " , )); // 对模板中变量赋值 $html_body = $tpl -> fetch( " star_html.tpl " );php_html( $html_body , $html_name ); // 将内容写入html文件 生成静态网页//模板中变理的赋值 常用语法//$USERBG.bg5 对数组元数单独引用 < {section name = LOOP loop = $BOOK } > < { $BOOK [LOOP] . visitor} > < { if ( $BOOK [LOOP] . replay_content) != '' } > < { $BOOK [LOOP] . replay_content} > < { / if } > < {sectionelse} > 无任何记录 ! < { / section} > // 利用 foreach 来呈现 array1 < { foreach item = item1 from = $array1 } > < { $item1 } > < { / foreach } > // 利用 section 来呈现 array1 < {section name = sec1 loop = $array1 } > < { $array1 [sec1]} > < { / section} > // 生成目录 function get_dir( $dir_name ){ if ( ! is_dir ( $dir_name )) { if ( mkdir ( $dir_name , 0777 )){ return true ; } else { return false ; } } } // 根据文件名生成多级目录 function get_dir( $filename ){ if ( strpos ( $filename , ' / ' )){ $dir_ary = explode ( ' / ' , $filename ); } else { $dir_ary [ 0 ] = $filename ; } $dir_str = "" ; for ( $i = 0 ; $i < count ( $dir_ary ); $i ++ ) { $dir_str .= $dir_ary [ $i ] . ' / ' ; if ( ! is_dir ( $dir_str )) { @ mkdir ( $dir_str ); // @mkdir($dir_str,0700)默认的 mode 是 0777 } } } // 层 <DIV style="Z-INDEX: 1; LEFT: 0px; POSITION: absolute; TOP: 0px"></div>//网页中内置flash < EMBED src = " bk.swf " quality = high wmode = " transparent " WIDTH = " 925 " HEIGHT = " 655 " TYPE = " application/x-shockwave-flash " > // 对javascript的引用<script src="../script/common.js"></script> < script language = " JavaScript " src = " ../script/menu.js " ></ script > 在 . js中一定不能加 < script > 否则不能显示出来,狂晕喔! // 教训 遍历循环不能忘记! $rs -> MoveNext() if ( ! $rs ) print $db -> ErrorMsg(); else while ( ! $rs -> EOF) { $rs -> MoveNext(); } $rs -> Close(); // strip_tags 去掉html代码//多选择的跳转 onchange = " location='?p='+this.options[this.selectedIndex].value+'&g=kk' " // location 后面是javascript脚本,用字符串与本身的变量要用加号 //特殊符号 & " " & < < > > < select onChange = " location.href = '?sorttype='+this.value " > < option value = " default " > 最近发表 </ option > < option value = " lastanswer " > 最近回复 </ option > </ select > // javacript数组定义 fruit = new Array ( 3 ); // fruit=new Array(); fruit[ 0 ] = " 苹果 " ; fruit[ 1 ] = " 梨子 " ; fruit[ 2 ] = " 橘子 " ; // alert(fruit.valueOf());//alert(fruit.reverse().join(","));//alert(fruit.toString()); test1 = new Array ( " aa " , " ff " , " dd " );test3 = [ " cc " , " ff " , " gg " ]; // 网页重复代码的简化 < TD align = left id = " testcode " > kkkkk </ TD > < script > document . write(document . getElementById( ' testcode ' ) . innerHTML); </ script > // <iframe name="name" id="old_bg_iframe" src="about:blank" width="500" height="300" scrolling="no"></iframe>//重定向 window.location.href//显示文字说明: form . btnSUB . value = ' 正在上传文件... ' ; form . btnSUB . disabled = true ; return true ; < input name = " btnSUB " type = " Submit " value = " 上 传 " > // getMyParam('aid'); function getMyParam( $param , $method = ' pg ' ) { global $ $param ; switch ( $method ) { case ' p ' : if ( isset ( $_POST [ $param ])) $ $param = $_POST [ $param ]; break ; case ' g ' : if ( isset ( $_GET [ $param ])) $ $param = $_GET [ $param ]; break ; case ' c ' : if ( isset ( $_COOKIE [ $param ])) $ $param = $_COOKIE [ $param ]; break ; case ' s ' : if ( isset ( $_SESSION [ $param ])) $ $param = $_SESSION [ $param ]; break ; case ' f ' : if ( isset ( $_FILES [ $param ])) $ $param = $_FILES [ $param ]; break ; default : if ( isset ( $_POST [ $param ]) || isset ( $_GET [ $param ])) { $ $param = ( isset ( $_POST [ $param ])) ? $_POST [ $param ] : $_GET [ $param ]; } break ; }} // 面向对象//用法:$db = & new dbConnection(true,"mshow","111111"); class dbConnection { function dbConnection( $debug , $DB_DATABASE , $DB_PASS , $DB_HOST = " localhost " , $DB_USER = " root " , $DB_TYPE = " mysql " ) { $this -> DB_TYPE = $DB_TYPE ; $this -> DB_HOST = $DB_HOST ; $this -> DB_USER = $DB_USER ; $this -> DB_PASS = $DB_PASS ; $this -> DB_DATABASE = $DB_DATABASE ; $this -> debug = $debug ; } function getConnection() { global $db ; require_once ( " adodb.inc.php " ); if ( ! isset ( $db )) { $db = NewADOConnection( $this -> DB_TYPE); $db -> debug = $this -> debug; $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; if ( ! $db -> Connect( $this -> DB_HOST , $this -> DB_USER , $this -> DB_PASS , $this -> DB_DATABASE)) { die ( ' <a href="/" target="_top">服务器忙,请稍候再访问</a> ' ); } } return $db ; }} // connection database /* $DB_TYPE = "mysql"; $DB_HOST = "localhost"; $DB_USER = "mshow"; $DB_PASS = "testmshow"; $DB_DATABASE = "mshow"; */ function dbConnection( $debug = false ){ global $db ; if ( ! isset ( $db )) { global $DB_TYPE , $DB_HOST , $DB_USER , $DB_PASS , $DB_DATABASE ; require_once ( " adodb.inc.php " ); $db = NewADOConnection( " $DB_TYPE " ); $db -> debug = $debug ; $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; if ( ! $db -> Connect( " $DB_HOST " , " $DB_USER " , " $DB_PASS " , " $DB_DATABASE " )) { exit ( ' <a href="/" target="_top">服务器忙,请稍候再访问</a> ' ); } } return $db ;} // 产生新的tag /* insertBefore语法:Node insertBefore(in Node newChild,in Node refChild)raises(DOMException);newChild: 被插入的节点;refChild:插入在新节点前面的节点说明:在refChild代表的现有子节点的前面插入newChild节点。如果refChild为null,则把新节点插到资节点列表的末尾 */ < script > function fnAppend(){ var oNewNode = document . createElement( " DIV " );oList . appendChild(oNewNode); // oNewNode.innerText="html code"; oNewNode . innerHTML = " html code " ;} function Insert(){ var oNewNode = document . createElement( " DIV " );document . all . oList . insertBefore(oNewNode , 1 );oNewNode . innerText = " html code " ;} </ script > < div id = oList ></ div > < input type = " button " value = " Append Child " onclick = " fnAppend() " />< br /> < input type = " button " value = " InsertBefore " onclick = " Insert() " /> // 变化颜色 onmousemove = " this.bgColor='buttonface' " onmouseout = " this.bgColor='white' " // 含帧页面 调入某一页载入另外一页 < BODY onload = " javaScript:top.frames['right'].location='right.php'; " > // adodb insert $record = array (); $record [ " firstname " ] = " Bob " ; $record [ " lastname " ] = " Smith " ; $record [ " created " ] = time (); $insertSQL = $db -> GetInsertSQL( $rs , $record ); $db -> Execute( $insertSQL ); // adodb update $sql = " SELECT * FROM ADOXYZ WHERE id = 1 " ; $rs = $db -> Execute( $sql ); $record = array (); $record [ " firstname " ] = " Caroline " ; $record [ " lastname " ] = " Smith " ; $updateSQL = $db -> GetUpdateSQL( $rs , $record ); $conn -> Execute( $updateSQL ); $arr = array ( array ( ' Ahmad ' , 32 ) , array ( ' Zulkifli ' , 24 ) , array ( ' Rosnah ' , 21 ) ); $ok = $db -> Execute( ' insert into table (name,age) values (?,?) ' , $arr ); // adodb page 用查询数据库用 include_once ( ' adodb-pager.inc.php ' ); $sql = " select * from user_music " ; $pager = new ADODB_Pager( $db , $sql ); $pager -> Render( $rows_per_page = 5 ); // 生成cache文件// class name:GetCache// user method: $test = new GetCache();// $test->getCacheBody('','liansuo','','');//cache file: music.php //array name: USER_MUSIC//关于验证码////int mt_rand ( [int min, int max])//若没有指定乱数的最大及最小范围,本函数会自动的从 0 到 RAND_MAX 中取一个乱数//resource imagecreate ( int x_size, int y_size )//imagecreate() 返回一个图像标识符,代表了一幅大小为 x_size 和 y_size 的空白图像//int imagecolorallocate ( resource image, int red, int green, int blue) imagecolorallocate() 返回一个标识符,代表了由给定的 RGB 成分组成的颜色//int imagesetpixel(int im, int x, int y, int col);//本函数可在图片上绘出一点。参数 x、y 为欲绘点的坐标,参数 col 表示该点的颜色。 session_start ();@ header ( " Expires: 0 " );@ header ( " Cache-Control: private, post-check=0, pre-check=0, max-age=0 " , FALSE );@ header ( " Pragma: no-cache " ); function randString( $length ) { $hash = '' ; $chars = ' ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz ' ; $max = strlen ( $chars ) - 1 ; for ( $i = 0 ; $i < $length ; $i ++ ) { $hash .= $chars [ mt_rand ( 0 , $max )]; } return $hash ;} $rand_code = randString( 5 ); $im = imagecreate( 60 , 15 ); $background_color = imagecolorallocate ( $im , 200 , 200 , 200 ); for ( $i = 0 ; $i <= 128 ; $i ++ ) { $point_color = imagecolorallocate( $im , mt_rand ( 0 , 255 ) , mt_rand ( 0 , 255 ) , mt_rand ( 0 , 255 )); imagesetpixel( $im , mt_rand ( 0 , 62 ) , mt_rand ( 0 , 25 ) , $point_color );} for ( $i = 0 ; $i < strlen ( $rand_code ); $i ++ ) { $text_color = imagecolorallocate( $im , mt_rand ( 0 , 255 ) , mt_rand ( 0 , 128 ) , mt_rand ( 0 , 255 )); $x = 2 + $i * 12 ; $y = mt_rand ( 0 , 10 ); imagechar( $im , 5 , $x , 0 , $rand_code [ $i ] , $text_color );} // int imagechar(int im, int font, int x, int y, string c, int col);//本函数用来书写横向的字符。原点坐标 (0,0) 为图片的左上角,参数 font //表示字体的大小,从最小的 1 起,参数 x、y 是写入字符的坐标值,参数 c //为欲写出的字符,参数 col 为字的颜色。参数 im 表示图形的 handle。 $_SESSION [ ' admin_session_check_code ' ] = $rand_code ; header ( ' Content-type: image/png ' );imagepng( $im );imagedestroy( $im ); // 单击特效 < script > function selectAll(){ var cbs = document . all( " cb " ); if (cbs . length) { for ( var i = 0 ;i < cbs . length;i ++ ) { cbs . item(i) . click(); } } else document . all( " cb " ) . click();} function selectItem(obj , s){ if (s){ obj . parentElement . bgColor = " #ffcc00 " ; } else { obj . parentElement . bgColor = " #efefef " ; }} </ script > < table >< tr >< td > < INPUT type = checkbox value = 1 name = cb onclick = selectItem(this . parentElement , this . checked) > </ td ></ tr >< tr >< td > < INPUT type = checkbox value = 2 name = cb onclick = selectItem(this . parentElement , this . checked) > </ td ></ tr >< tr >< td > < INPUT onclick = selectAll() type = button value = " sure " > </ td ></ tr > < table > // 获得等比例的照片 function image_size( $file , $setwidth , $setheight ){ // round -- 对浮点数进行四舍五入 $image = getImageSize ( $file ); $new_width = $image [ 0 ]; $new_height = $image [ 1 ]; if ( $image [ 0 ] > $setwidth ){ $new_width = $setwidth ; $new_height = round ( $image [ 1 ] / $image [ 0 ] * $setwidth ); } if ( $new_height > $setheight ){ $new_width = round ( $new_width / $new_height * $setheight ); $new_height = $setheight ; } return array ( $new_width , $new_height );} // 图片加水印及缩小图片处理//http://sourceforge.net/projects/image-toolbox include_once ( " Image_Toolbox.class.php " ); $file = " test.jpg " ; $img = new Image_Toolbox( $file ); list ( $new_width , $new_height ) = image_size( $file , 200 , 200 ); $img -> newOutputSize( $new_width , $new_height ); /* $text= "www.mshow.com.cn"; $color= "#000000";$valign= "bottom"; $halign= "center"; $font = "arial.ttf";$size = "10";$img->addText($text, $font, $size, $color, $halign, $valign); */ $img -> addImage( " add.gif " ); // 合成图 $img -> blend( ' right -10 ' , ' bottom -5 ' ); // $img->output('jpg'); $img -> save( " newimag1e.jpg " ); // 取得文件后缀名 //echo get_Suffix("fdsgdsgfds"); function get_Suffix( $file ){ if (( $str_pos = strrpos ( $file , " . " )) == true ){ return strtolower ( substr ( $file , $str_pos + 1 )); } else { return false ; }} // javascript get suffix mp3 i.g. var s = " http://www.163.com/1.mp3 " ; var last_word = s . substring(s . lastIndexOf( " . " ) + 1 , s . length); // 选择下拉框函数// $selected_value 格式为 id1,id2,id3// $param_str 是<select 里面需要的其它参数,如onChange事件,style属性等//echo showInputBox($category_list_ary,"catagory_class_id","","select_box"); function showInputBox( $input_ary , $input_name , $selected_value = '' , $input_type = ' checkbox ' , $select_box_default = ' <option value="">请选择</option> ' , $param_str = '' , $break_num = 5 ){ $s = '' ; $i = 1 ; $selected_ary = explode ( ' , ' , $selected_value ); while ( list ( $key , $val ) = each ( $input_ary )) { if ( $input_type == ' select_box ' ) { $selected_str = ( $selected_value != '' && in_array ( $key , $selected_ary )) ? ' selected ' : '' ; $s .= ' <option value= ' . $key . $selected_str . ' > ' . $val . ' </option> ' . NL; } else { $selected_str = ( $selected_value != '' && in_array ( $key , $selected_ary ) ) ? ' checked ' : '' ; $s .= ' <input type= ' . $input_type . ' name= ' . $input_name . ' value= ' . $key . $selected_str . ' ' . $param_str . ' > ' . $val . NL; } if ( $input_type != ' select_box ' && $i % $break_num == 0 ) $s .= ' <br> ' ; $i ++ ; } if ( $input_type == ' select_box ' ) { $s = ' <select name= ' . $input_name . ' ' . $param_str . ' > ' . NL . $select_box_default . NL . $s . NL . ' </select> ' . NL; } return $s ;} // onclick事件 更新数据之前提醒用户 onclick = " javascript:if (confirm('你确定设置为公开状态吗')) location='?action=update&id='.$rs->fields[ " id " ].'&public=0' " // // Checkbox Switcher// return checked number and checked value string(like 3,5,9,11)// Example: <input type=button value="switch" onClick="switchCheckbox('',form,form.C1)">// Example: <input type=button value="switch" onClick="switchCheckbox('',"C1[]")">// Write by Macro Zeng macroz@gmail.com http://www.dyddy.com function switchCheckbox(type , f , o) { var checked_ary = Array ( 0 , '' ); if ( typeof(o) == " object " ) { switch (type) { case ' all ' : for ( i = 0 ; i < o . length; i ++ ) { o[i] . checked = true ; } break ; case ' empty ' : for ( i = 0 ; i < o . length; i ++ ) { o[i] . checked = false ; } break ; case ' switch ' : for ( i = 0 ; i < o . length; i ++ ) { o[i] . checked = ! o[i] . checked; } break ; } for ( i = 0 ; i < o . length; i ++ ) { if ( o[i] . checked == true ) { checked_ary[ 0 ] ++ ; checked_ary[ 1 ] += f . elements[i] . value + ' , ' ; } } } else { switch (type) { case ' all ' : for ( i = 0 ; i < f . elements . length; i ++ ) { if ( f . elements[i] . type == ' checkbox ' && f . elements[i] . name . indexOf(o) != - 1 ) { f . elements[i] . checked = true ; } } break ; case ' empty ' : for ( i = 0 ; i < f . elements . length; i ++ ) { if ( f . elements[i] . type == ' checkbox ' && f . elements[i] . name . indexOf(o) != - 1 ) { f . elements[i] . checked = false ; } } break ; case ' switch ' : for ( i = 0 ; i < f . elements . length; i ++ ) { if ( f . elements[i] . type == ' checkbox ' && f . elements[i] . name . indexOf(o) != - 1 ) { f . elements[i] . checked = ! f . elements[i] . checked; } } break ; } for ( i = 0 ; i < f . elements . length; i ++ ) { if ( f . elements[i] . type == ' checkbox ' && f . elements[i] . name . indexOf(o) != - 1 && f . elements[i] . checked == true ) { checked_ary[ 0 ] ++ ; checked_ary[ 1 ] += f . elements[i] . value + ' , ' ; } } } if ( checked_ary[ 1 ] != '' ) { checked_ary[ 1 ] = checked_ary[ 1 ] . substr ( 0 , checked_ary[ 1 ] . length - 1 ); } return checked_ary;} // 全选删除 function validcheck(action , form) { var checked_num = switchCheckbox( '' , form , ' id[] ' )[ 0 ]; if (checked_num == "" || checked_num == 0 || checked_num == null ) { alert( " 请选择要操作选项! " ); return false ; } else { if (confirm( " 你确定要删除所选择的记录吗? " )){ form . action = " ?action= " + action; form . submit(); } else { return false ; } }} < form name = "" action = "" method = " post " > < input type = " checkbox " name = " id[] " value = " ' .$rs->fields['id']. ' " > < input type = " button " value = " 全选 " onclick = " switchCheckbox('all',form,'id[]') " > < input type = " button " value = " 清空 " onclick = " switchCheckbox('empty',form,'id[]') " > < input type = " button " value = " 反选 " onclick = " switchCheckbox('switch',form,'id[]') " > < input type = " button " value = " 删除所选项 " onclick = " return validcheck('del',this.form) " > </ form > getMyParam( ' action ' ); if ( $action == " del " ) { getMyParam( ' id ' ); if ( isset ( $id ) && is_numeric ( $id ) && $id > 0 ) { if ( $db -> Execute( " DELETE FROM user_book WHERE id=$id " ) == true ){ goBack( " 删除记录成功! " , " book_manage.php " ); } } if ( isset ( $id ) && is_array ( $id ) && count ( $id ) > 0 ){ for ( $i = 0 ; $i < count ( $id ); $i ++ ){ $sql = " delete from user_book where id= " . $id [ $i ]; $db -> Execute( $sql ); } goBack( " 删除记录成功! " , " book_manage.php " ); } } // 初始化 $select_str = " where 1 = 1 " ; // 显示记录 $pg = new show_page; $pg -> setPageVar( ' p ' ); $pg -> setNumPerPage( 20 ); $sql_nums = " SELECT COUNT(id) FROM photo " . $select_str ; $record_nums = $db -> GetOne( $sql_nums ); $pg -> setVar( $set_var ); $pg -> set( $record_nums ); $show_pages = $pg -> output( 1 ); $str = '' ; if ( $record_nums > 0 ) { $sql = " SELECT * FROM photo " . $select_str ; if ( ! $rs = $db -> SelectLimit( $sql , $pg -> getNumPerPage() , $pg -> getOffset())) { echo $db -> ErrorMsg(); $db -> Close(); exit (); } while ( ! $rs -> EOF) { $str .= ' <form name="" action="" method="post" > ' ; $rs -> MoveNext(); } $rs -> Close(); $str .= ' <tr><td colspan="" align="center"> ' . $show_pages . ' </td></tr> <tr><td colspan="" align="center"> <input type="button" value="全选" οnclick="switchCheckbox('all',form,'id[]')"> <input type="button" value="清空" οnclick="switchCheckbox('empty',form,'id[]')"> <input type="button" value="反选" οnclick="switchCheckbox('switch',form,'id[]')"> <input type="button" value="删除所选项" οnclick="return validcheck('del',this.form)"> </td></tr> </form> ' ;} else { $str .= ' <tr><td colspan="">暂无任何记录</td></tr> ' ;} // 判断某条记是否数字 function check(form) { var id = form . id . value; if (id != null && isNaN(id)){ alert( " ID必须为数字 " ); return false ; }} // 搜索记录 < form name = " form1 " method = " post " action = " ?action=search " onsubmit = " return check(this) " > < table width = " 100% " border = " 1 " cellspacing = " 1 " align = " center " > < tr > < td align = " center " > < input type = " submit " name = " Submit " value = " 搜索 " ></ td > </ tr > </ table > </ form > // 同一页面修改某条记录 function editGroup(id , title){ // document.all("id").value=id; document . all( " title " ) . value = title; document . all( " title_ " ) . innerText = title; editform . style . display = "" ; document . all( " title " ) . focus(); document . all( " title " ) . select();} < a href = " javascript:editGroup(' .$rs->fields['id']. ','' .$rs->fields['title']. '') " > 修改 </ a > < div id = " editform " style = " z-index:100;display:none; " > < fieldset style = " width:500;padding:5px " > < legend > 修改“ < span id = " title_ " style = " color:red " ></ span > ”分类 :</ legend > < form action = " ?action=edit " method = " post " onsubmit = "" name = " addform " > < input type = " Text " name = " title " >& nbsp; < input type = " Submit " value = " 修 改 " > < input type = " Button " value = " 取 消 " onclick = " return editform.style.display='none'; " > </ form > </ fieldset > </ form > </ div > // 删除技巧 < a href = " javascript:if(confirm('确定删除此记录吗?'))location='?action=del&id=' . $rs->fields['id'] . ' " > 删除 </ a > // css 学习 body{ font - size : 9pt; color : # ffffff; font - family : " 宋体 " ; background - color : 306f8f; } td{ FONT - FAMILY : " Verdana " ; // color : # 3333333; letter - spacing : 1pt ; line - height : 14pt; // 即字体最底端与字体内部顶端之间的距离。 WORD - BREAK : break - all; // 也允许非亚洲语言文本行的任意字内断开。 font - size : 14px; line - height : 20px;}hr { height : 1px; color : # 66CC66 }A {text - decoration : none; font - family : 宋体;} A : link {text - decoration : none; color : # FFFF00}//decoration n.装饰物 A : visited {text - decoration : none; color : # CCFF00} A : hover {text - decoration : underline; color : # FF0000;} select{ font - size : 8pt; font - family : verdana; background - color : # ffffff; border : 0px dotted # cccccc; color : # 333333; }textarea , input{ font - size : 8pt; font - family : verdana; background - color : # ffffff; border : 1px dotted # cccccc; color : # 333333;letter-spacing : 1pt ; line - height : 150 % } . f{ color : # ffffff; height : 1pt; filter : shadow(color = yellow , direction = 120 ) FONT - FAMILY : " Verdana " ; FONT - SIZE : 11pt;letter - spacing : 2pt} // style效果 < tr onmousemove = " this.bgColor='buttonface' " onmouseout = " this.bgColor='white' " > < STYLE type = text / css > . title { PADDING - LEFT : 10px; FONT - WEIGHT : bold; FONT - SIZE : 14px; COLOR : white; BACKGROUND - COLOR : # 535353 //设置或检索对象中的文本字体的粗细。 } </ STYLE > // 删除文件 if ( file_exists ( $file_path )) @ unlink ( $file_path ); // 魔术符号的处理//如果magic_quotes_gpc=Off,那就为提单提交的$_POST['message']里的敏感字符加反斜杠//magic_quotes_gpc=On的情况下,则不加 if ( ! get_magic_quotes_gpc ()) { $_POST [ ' message ' ] = addslashes ( $_POST [ ' message ' ]);} else {} // 按时间搜索总结 strtotime 前后一天之间 if ( isset ( $add_date ) && $add_date != '' ){ if ( ! ereg ( " ([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) " , $add_date )) { goback( " 时间格式不对 " ); return false ; } else { $select_str .= ' and add_date between ' . ( strtotime ( $add_date ) - 86400 ) . ' and ' . ( strtotime ( $add_date ) + 86400 ) . '' ; $set_var [ ' add_date ' ] = $add_date ; } } $select_str .= ' and name like ' . $db -> qstr( ' % ' . trim ( $keyword ) . ' % ' ); // 验证是否为全中文 $str = " 超越PHP " ; if ( preg_match ( " /^[ " . chr ( 0xa1 ) . " - " . chr ( 0xff ) . " ]+$/ " , $str )) { echo " 这是一个纯中文字符串 " ;} else { echo " 这不是一个纯中文字串 " ;} // mktime 总结 //取得一个日期的 UNIX 时间戳//包含了从 Unix 新纪元(1970 年 1 月 1 日)到给定时间的秒数。 $k = mktime ( $hours + 24 , $minutes , $seconds , $month , $day , $year ); echo " 2006-5-15 5:25:38 " . ' <br> ' ; echo date ( " Y-n-j H:i:s " , $k ); // 数据库中插入当前时间 date ( " Y-m-d H:i:s " ) // 判断数据库是否有记录存在 if ( $db -> GetOne( $sql ) == true ){ goBack( " 己有记录!! " , "" );} // 保存now() field 为datetime//查询用 ' and DATE_FORMAT(send_date, "%Y-%c-%e") = "' .$send_date .'"';//对接收数组打印技巧 echo ' <pre> ' ; print_r ( $_POST ); echo ' </pre> ' ; // 按时间搜索 i.g. 2005-6-26 //起止中止时间 $start_date_timestamp = 0 ; if ( isset ( $start_date ) && substr_count ( $start_date , ' - ' ) == 2 ) { $start_date_ary = explode ( ' - ' , $start_date ); if ( checkdate ( $start_date_ary [ 1 ] , $start_date_ary [ 2 ] , $start_date_ary [ 0 ]) ) { $start_date_timestamp = mktime ( 0 , 0 , 0 , $start_date_ary [ 1 ] , $start_date_ary [ 2 ] , $start_date_ary [ 0 ]); $select_str .= ' AND add_date>= ' . $start_date_timestamp . ' ' ; $set_var [ ' start_date ' ] = $start_date ; }} if ( isset ( $end_date ) && substr_count ( $end_date , ' - ' ) == 2 ) { $end_date_ary = explode ( ' - ' , $end_date ); if ( checkdate ( $end_date_ary [ 1 ] , $end_date_ary [ 2 ] , $end_date_ary [ 0 ]) ) { $end_date_timestamp = mktime ( 23 , 59 , 59 , $end_date_ary [ 1 ] , $end_date_ary [ 2 ] , $end_date_ary [ 0 ]); if ( $end_date_timestamp > $start_date_timestamp ) { $select_str .= ' AND add_date<= ' . $end_date_timestamp . ' ' ; $set_var [ ' end_date ' ] = $end_date ; } }} // 生成js技巧 里面不能再带script $body = ' document.write("彩信批发总计: ' . $sum . ' <br>"); ' . NL; $body .= ' document.write("所有批发彩信店剩余彩信总计: ' . $leave_sum . ' <br>"); ' . NL; $body .= ' document.write("脚本更新时间: ' . date ( " y-n-j H:i:s " ) . ' "); ' . NL; $fp = fopen ( " sum.js " , " w " ); fwrite ( $fp , $body ); fclose ( $fp ); // 背景音乐播放 oBgSound.Play() oBgSound.Pause() oBgSound.Filename=url; < object id = " oBgSound " classid = " clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95 " id = " MediaPlayer1 " > < param name = " AutoStart " value = " 1 " > < param name = " PlayCount " value = " 0 " > < param name = " Filename " value = "" > </ object > // 环境搭建//php.ini extension = php_gd2 . dllextension = php_mysql . dllSMTP = localhostsmtp_port = 25 include_path = " .;D:phpserveradodb;D:phpserverSmarty " extension_dir = " D:/php/ext " // C:WINDOWSsystem32driversetcHosts 127.0 . 0.1 localhost 127.0 . 0.1 home3 . mshow . com . cn 192.168 . 1.132 home2 . mshow . com . cnD : Apache2confhttpd . confLoadModule php5_module " D:/php/php5apache2.dll " AddType application / x - httpd - php . php . phtml . php3 . php4AddType application / x - httpd - php - source . phpsAddType application / x - compress . ZAddType application / x - gzip . gz . tgzServerName www . mshow . com . cn : 80 DocumentRoot " D:/Apache2/htdocs " < Directory " D:/Apache2/htdocs " > UserDir " My Documents/My Website " DirectoryIndex index . php index . html index . htm index . html . var ErrorLog logs / error . log CustomLog logs / access . log commonAlias / icons / " D:/Apache2/icons/ " Alias / phpMyAdmin " E:/web/phpMyAdmin/ " < VirtualHost *: 80 > ServerAdmin webmaster@mshow . com . cn DocumentRoot E :/ web ServerName localhost ErrorLog logs / localhost - error_log CustomLog logs / localhost - access_log common </ VirtualHost > < VirtualHost *: 80 > ServerAdmin webmaster@mshow . com . cn DocumentRoot E :/ web / bbsaaa ServerName test3 . mshow . com . cn ErrorLog logs / www . mshow . com . cn - error_log CustomLog logs / www . mshow . com . cn - access_log common </ VirtualHost > < Directory " E:/web " > Options Indexes FollowSymLinks AllowOverride None Order allow , deny Allow from all </ Directory > // 两级目录的显示js显示 < form name = " form1 " method = " get " > < SELECT onchange = " show_liansuo(this.value, 0, form.ls_id) " size = 1 name = " province_id " > < option value = " 0 " > 不限 </ option > </ SELECT > < SELECT size = 1 name = " ls_id " > < OPTION selected value = "" > 不限 </ OPTION > </ SELECT >< input type = submit value = " 搜索 " > </ form > < script > province_ary = new Array ( Array ( " 28 " , " 北京 " ) , Array ( " 28 " , " 天津 " ) , Array ( " 28 " , " 广西 " ));liansuo_ary_28 = new Array ( Array ( " 211 " , " 南宁快乐影吧万达旗舰店全国样板店 " ) , Array ( " 238 " , " 南宁女人世界快乐影吧全国样板店 " ) , Array ( " 497 " , " 七彩影吧 " )); function show_province(p_box , p_id) { for (m = p_box . options . length - 1 ;m > 0 ;m -- ) { p_box . options[m] = null } p_box . options[ 0 ] = new Option( " 请选择省份 " , "" ); selected_option = 0 ; for (i = 0 ;i < province_ary . length;i ++ ){ if ( p_id == province_ary[i][ 0 ] ) { selected_option = i + 1 ; } p_box . options[i + 1 ] = new Option(province_ary[i][ 1 ] , province_ary[i][ 0 ]) } p_box . options[selected_option] . selected = true } function show_liansuo(p_id , c_id , c_box) { for (m = c_box . options . length - 1 ;m > 0 ;m -- ) { c_box . options[m] = null } c_box . options[ 0 ] = new Option( " 请选择店名 " , "" ); if (p_id > 0 ) { selected_option = 0 ; group = eval ( " liansuo_ary_ " + p_id); for (i = 0 ;i < group . length;i ++ ){ if ( c_id == group[i][ 0 ] ) { selected_option = i + 1 ; } c_box . options[i + 1 ] = new Option(group[i][ 1 ] , group[i][ 0 ]); } c_box . options[selected_option] . selected = true }}show_province(document . form1 . province_id , 0 );show_liansuo( 0 , 0 , document . form1 . ls_id); </ script > // 设置字体颜色 document . getElementById( '' ) . classNamedocument . getElementById( "" ) . innerHTML // 自身关闭 onclick = " self.close() " // title加关键字 便于搜索 < META NAME = " description " CONTENT = " 国内首推的个人门户,一张可以随时编辑的网上名片;个人门户,帮助用户全方位展示自我,集成了博客、图片、博揽RSS、网摘等几大产品;系统速度超快,功能强大,傻瓜化操作,模板和个性化定制功能极丰富;不但人气旺盛,还可以交友、赚钱、拉帮结派…… " > < META NAME = " keywords " CONTENT = " 个人门户、个人名片、网络名片、社区、SN、博客、Blog、网摘、图片、照片、RSS、收藏、共享、分享、日志、blogger、社区、BBS、时政、社会、历史、股票、期货、外汇、理财、经济、管理、传媒、房产、汽车、IT、科学、电影、电视、娱乐八卦、笑话、旅游、摄影、婚恋、男性、女性、重读历史、股票、分析师、谈股论金 " > // ajax 技术总结 xmlhttprequest.js//下载http://www.scss.com.au/family/andrew/webdesign/xmlhttprequest///i.g. < script type = " text/javascript " src = " js/xmlhttprequest.js " ></ script > < script > function showContent() { document . getElementById( " example " ) . parentNode . style . display = "" ; var req = new XMLHttpRequest(); if (req) { req . onreadystatechange = function () { // readyState 0 = 未初始化1 = 读取中2 = 已读取3 = 交互中4 = 完成 if (req . readyState == 4 && (req . status == 200 || req . status == 304 )) { document . getElementById( " example " ) . innerHTML = req . responseText; } else { document . getElementById( " example " ) . innerHTML = " 正在读取数据... " } }; // req.open('GET', "1.php?username='罗小强'&age=23");//method get req . open( ' POST ' , ' 1.php ' ); // method post req . setRequestHeader( ' Content-Type ' , ' application/x-www-form-urlencoded; charset=UTF-8 ' ); // req.send(null); req . send( " username=罗小强&age=23 " ); }} </ script > // 在body之间加上 否则出错 < body > < div style = " display:none " > < div id = " example " ></ div > </ div > < script language = javascript > showContent(); </ script > </ body > // 读取目录,并以特定格式返回此目录下所有文件 /* $dir='../../music';$file_formate="mp3";$ary = get_array($dir,$file_formate);echo "<pre>";print_r($ary);echo "</pre>"; */ function get_array( $dir , $file_formate ){ $ary = array (); if ( $fp = opendir ( $dir )) { while ( false !== ( $file = readdir ( $fp ))) { if ( is_file ( $dir . ' / ' . $file )){ if (( $str_pos = strrpos ( $file , " . " )) == true ){ if ( strtolower ( substr ( $file , $str_pos + 1 )) == $file_formate ) { $ary [] = $file ; } } } } closedir ( $fp ); } return $ary ;} ?>