免费注册 查看新帖 |

Chinaunix

广告
  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2074 | 回复: 0
打印 上一主题 下一主题

06-07php开发记录 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-06-19 22:59 |只看该作者 |倒序浏览

   
   
   
外面不能留空行
//jsonrpc, dwr, buffalo, prototype
/*解决Warning: Cannot modify header information - headers already sent by ......
打开 php.ini 然后把 output_buffering 设为 on 。重起appache,OK。
ob_start();*/
//技术小结
//常量定义
define('NL', " ");
//乱码  
__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?\:\/\/[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'];
//
// 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 ' Your order could not be processed at this time.  '
       .'Please try again later.';
  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 'No orders pending.'
         .'Please try again later.';
     exit;
   }
   while (!feof($fp))
   {
      $order= fgets($fp, 999);
      echo $order.'
';
   }
echo 'Final position of the file pointer is '.(ftell($fp));
echo '
';
rewind($fp);
echo 'After rewind, the position is '.(ftell($fp));
echo '
';
fclose($fp);
//验证非法字符 name传进的字符传
function validchars(str)
{
var str_match = "^&*;'‘";
   for(i=0;iExecute('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('数据库错误,请访问其它页面');
}
//
$db->ErrorMsg();
$recordSet->Close(); # optional
$db->Close(); # optional
if ($conn->Execute($sql) === false) {
        print 'error inserting: '.$conn->ErrorMsg().'
';
}
//设为首面/加入收藏开夹
/*
收藏[我的导航]
设为首页
*/
//换行用   
//所有的祸与福皆从口出,所以事事必谨言慎行,切记
//遍历循环
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 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 []
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");
function chageDiv()
{
  document.getElementById("div1").innerHTML = "值为1";
}
DIV块测试:默认值
改变值为1
#########################
document.getElementById("select_bg").innerHTML = document.getElementById("system_skin2").innerHTML;
document.getElementById("select_bg").style.display = '';
 
代码显示区域
//得到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);
    }
}
//
var article = new Array(Array(1,'心情故事'),Array(2,'随想录'),Array(3,'转载'));
function show_category()
{
    document.write("");
    var selectTag = category;
    selectTag.options.length=0;
    for(i = 0;i
//图层设置透明度
); 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","台湾"));
*/
//~!@#$%^&*()_+}{":?>]*>)(.*)()/",
$html_str, $matches);//索目标中所有匹配,然后按照指定顺序放到结果数组中.
如果找到第一个匹配,则后续的匹配从上一个匹配结尾处开始搜
?>

";}
}?>

[删除]
/*
    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'].'
';
    $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  = "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 对数组元数单独引用
无任何记录!
//利用 foreach 来呈现 array1
      
      
      
//利用 section 来呈现 array1
      
      
      
//生成目录
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
//网页中内置flash
// 对javascript的引用
在.js中一定不能加否则不能显示出来,狂晕喔!
//教训 遍历循环不能忘记! $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脚本,用字符串与本身的变量要用加号
//特殊符号  &amp "  &quot &  &lt
最近发表
最近回复
//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"];
//网页重复代码的简化
kkkkk
document.write(document.getElementById('testcode').innerHTML);
//
//重定向  window.location.href

//显示文字说明:
form.btnSUB.value='正在上传文件...';
        form.btnSUB.disabled=true;
        return true;
//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('服务器忙,请稍候再访问');
            }
        }
        return $db;
      }
}
//////////////////////////////////
mysql_connect("localhost", "root", "") or
        die("Could not connect: " . mysql_error());
    mysql_select_db("mysql");
    $result = mysql_query("SELECT help_keyword_id , name FROM help_keyword");
    while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
        printf ("ID: %s  Name: %s
", $row[0], $row[1]);
    }
mysql_free_result($result);
/////////////////////////////////
//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('服务器忙,请稍候再访问');
        }
    }
    return $db;
}
//产生新的tag
/*
insertBefore
语法:
Node insertBefore(in Node newChild,in Node refChild)
raises(DOMException);
newChild: 被插入的节点;
refChild:插入在新节点前面的节点
说明:在refChild代表的现有子节点的前面插入newChild节点。如果refChild为null,则把新节点插到资节点列表的末尾
*/
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";
}
//变化颜色
onmousemove="this.bgColor='buttonface'" onmouseout ="this.bgColor='white'"
//含帧页面 调入某一页载入另外一页
//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
function selectAll()
{
    var cbs=document.all("cb");
    if(cbs.length)
    {
        for(var i=0;i


//获得等比例的照片
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 是请选择', $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 .= '' .  $val . '' . NL;
        } else {
            $selected_str = ($selected_value != '' && in_array($key, $selected_ary) ) ? ' checked ' : '';
           
$s .= ''  . $val .
NL;
        }
        if ($input_type != 'select_box' && $i % $break_num == 0) $s .= '
';
        $i++;
    }
    if ($input_type == 'select_box') {
      
$s = '' . NL
. $select_box_default . NL . $s . NL . '' . NL;
    }
    return $s;
}
//onclick事件 更新数据之前提醒用户
id"].'&public=0'"
//// Checkbox Switcher
// return checked number and checked value string(like 3,5,9,11)
// Example:
// Example:
// 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
fields['id']. '">
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  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 .= '
            
                ';
   
         $rs->MoveNext();
    }
    $rs->Close();
    $str .= '
            ' .$show_pages. '
            
            
            
            
            
            
            
            ';
} else {
    $str .= '暂无任何记录';
}
//判断某条记是否数字
function check(form) {
   var id = form.id.value;
   if (id != null && isNaN(id)){
        alert("ID必须为数字");
        return false;
    }
}
//搜索记录

//同一页面修改某条记录
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();
}
fields['id']. ','' .$rs->fields['title']. '')">修改
修改“”分类:
 
//删除技巧
fields['id'] . '">删除
//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效果
.title {
    PADDING-LEFT: 10px; FONT-WEIGHT: bold; FONT-SIZE: 14px; COLOR: white; BACKGROUND-COLOR: #535353  //设置或检索对象中的文本字体的粗细。
}
//删除文件
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".'
';
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 '';
print_r($_POST);
echo '';
//按时间搜索 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
   
   
   
//环境搭建
//php.ini
extension=php_gd2.dll
extension=php_mysql.dll
SMTP = localhost
smtp_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.cn
D:Apache2confhttpd.conf
LoadModule php5_module "D:/php/php5apache2.dll"
AddType application/x-httpd-php .php .phtml .php3 .php4
AddType application/x-httpd-php-source .phps
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
ServerName
www.mshow.com.cn:80
DocumentRoot "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 common
Alias /icons/ "D:/Apache2/icons/"
Alias /phpMyAdmin "E:/web/phpMyAdmin/"
    ServerAdmin
webmaster@mshow.com.cn
    DocumentRoot E:/web
    ServerName localhost
    ErrorLog logs/localhost-error_log
    CustomLog logs/localhost-access_log common
    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
    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
//两级目录的显示js显示
不限
不限
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;i0;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
//设置字体颜色
document.getElementById('').className
document.getElementById("").innerHTML
//自身关闭
//title加关键字 便于搜索
//ajax 技术总结  xmlhttprequest.js
//下载
http://www.scss.com.au/family/andrew/webdesign/xmlhttprequest/
//i.g.
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");
    }
}
//在body之间加上 否则出错
showContent();
//读取目录,并以特定格式返回此目录下所有文件
/*$dir='../../music';
$file_formate="mp3";
$ary = get_array($dir,$file_formate);
echo "";
print_r($ary);
echo "";*/
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;
}
?>
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/86601/showart_1970929.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP