首页 > PHP教程

php 日期转换成日时截

php 日期转换成日时截

private function toTimeStamp ($dateTimeString = NULL) {
  if (!$dateTimeString) {
   $dateTimeString = time();
  }
  $numeric = ;
  $add_space = false;
  for($i=0;$i<strlen($dateTimeString);$i++) {
   if(strpos(0123456789,$dateTimeString[$i])===false) {
    if($add_space) {
     $numeric .= ;
     $add_space = false;
    }
   } else {
    $numeric .= $dateTimeString[$i];
    $add_space = true;
   }
  }
  
  $numeric_array = explode( ,$numeric,6);
  if(sizeof($numeric_array)<3 || ($numeric_array[0]==0 && $numeric_array[1]==0 && $numeric_array[2]==0)) {
   throw new Exception($dateTimeString . is an invalid parameter, 5);
  } else {
   $result = mktime(intval($numeric_array[3]), intval($numeric_array[4]), intval($numeric_array[5]),
        intval($numeric_array[1]), intval($numeric_array[2]), intval($numeric_array[0])) ;
  }
  
  return $result;
 
 }

阅读全文

php google 风格分页代码

php  google 风格分页代码
public function showCtrlPanel_g($halfPer = 5) {
  
  $re = <div class="pageMore">
   <ul>
    <li><span>.$this->lineCount.条</span></li>
    <li><span>.$this->currentPage./.$this->pageCount.页</span></li>;
  if($this->currentPage-$halfPer >1){
   $re .= <li><a href=".$this->fileName.pageno=1"><span>1</span></a></li>;
   if($this->currentPage-$halfPer*2 >1){
    $re .= <li><a href=".$this->fileName.pageno=.($this->currentPage-$halfPer*2)."><span>...</span></a></li>;
   }else{
    $re .= <li><a href=".$this->fileName.pageno=1"><span>...</span></a></li>;
   }
  }
  for ( $i = $this->currentPage - $halfPer,$i > 1 || $i = 1 , $j = $this->currentPage + $halfPer, $j < $this->pageCount || $j = $this->pageCount;$i <= $j ;$i++ )
  {
   $re .= $i ==  $this->currentPage
    ? <li class="linkOn"><a href=".$this->fileName.pageno=.$i."><span>.$i.</span></a></li>." "
    : <li><a href=".$this->fileName.pageno=.$i."><span>.$i.</span></a></li>." ";
  }
  if($this->currentPage+$halfPer < $this->pageCount){
   if($this->currentPage+$halfPer*2 < $this->pageCount){
    $re .= <li><a href=".$this->fileName.pageno=.($this->currentPage+$halfPer*2)."><span>...</span></a></li>;
   }else{
    $re .= <li><a href=".$this->fileName.pageno=.$this->pageCount."><span>...</span></a></li>;
   }
   $re .= <li><a href=".$this->fileName.pageno=.$this->pageCount."><span>.$this->pageCount.</span></a></li>;
  }
    
  $re .=  
   </ul>
  </div>;
  return $re;
 }

阅读全文

php getimagesize

php getimagesize

getimagesize是读取图片相关信息,返回一个具有四个单元的数组。索引 0 包含图像宽度的像素值,索引 1 包含图像高度的像素值。索引 2 是图像类型的标

阅读全文

php mage2wbmp 函数

image2wbmp
(PHP 4中“= 4.0.5,PHP 5中)

image2wbmp - 输出图像浏览器或文件

报告错误描述
布尔image2wbmp($oimg[,$filename[,soruce]])
image2wbmp()输出或保存一个给定的图像WBMP版本。

报告错误参数

图片
图像资源,通过创造的图像功能,如,一返回imagecreatetruecolor()。

文件名
路径保存的文件。如果没有给出原始图像流将被直接输出。

开始
阈值介于0和255(含)。


报告错误返回值
返回TRUE,成功或失败则返回FALSE。

报告错误的例子

阅读全文

php列出数据再用js 删除数据

php列出数据再用js 删除数据

<?php
include("../inc/inc.php");
islogin();
$Db = new Db();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>增加城市分类</title>
<!-- at:jimmy email:mailangel123@163.com -->

阅读全文

php 批量增加数据

php 批量增加数据
下面我们是测试一个php批量增加城市的代码以"|"分开哦。
function Addtype()
 {
  if( $_FILES ){exit;}
  $info =;
  $cityname = trim(PostGet(cityname,1));
  $citytype = trim(PostGet(citytype,1));
  $orderid = trim(PostGet(orderid,1));
  
  if( $cityname ==0 || !is_numeric( $cityname ) )
  {
   MessAge(请选择城市);
  }
  elseif(strlen($citytype) <2 )
  {
   MessAge(输入城市地区); 
  }
  elseif( !is_numeric($orderid ))
  {
   MessAge(对不起,排序必须是数字哦!);
  }
  
  if( strpos($citytype,|)!=false)
  {
   $array = explode(|,$citytype);
   if( is_array( $array ) )
   {
    $array = array_filter($array,filter);    
   }
  }
  else
  {
   $array = $citytype;
  }
  $Db= new Db();
  $d =date("Y-m-d");
  if( is_array( $array ) )
  {
   foreach( $array as $v => $_v )
   {
    $row = $Db->query("Select * from 111cn_city where upid=$cityname and cntitle=".$_v."");
    if( $Db->rows( $row ) )
    {
     $info.=$_v.,;
    }
    else
    {
     try{
      $Db->query("Insert into 111cn_city(cntitle,upid,orderid,createdate)values($_v,$cityname,$orderid,$d)");
      
     }catch (Exception $e){
      MessAge(操作失败!);
     }      
    }    
   }
   MessAge("增加成功,失败有$info",addtype.php);
  }
  else
  {
   $Query = $Db->query("select * from 111cn_city where upid=$cityname and cntitle=$array");
   if( $Db->rows( $Query ) )
   {
    MessAge("对不起,你所要增加的城市[$array]己存在php了");
   }
   else
   {
    try{     
     $Db->query("Insert into 111cn_city(cntitle,upid,orderid,createdate)values($array,$cityname,$orderid,$d)");
     MessAge(操作成功,addtype.php);
    }catch (Exception $e){
     MessAge(失败成功);
    }
   }
  }
   
 }

阅读全文

[原创]php数据库连接类

[原创]phpphp连接类

<?php
 class Db{ 
  public $conn;
  public $root=localhost;
  public $user=root;
  public $pass=root;
  public $db=111cn.cn;
  public $charset=gb2312;
  public $links=c;
  
  function __construct() {
    $this->connect();
  }
  
  function connect()
  {
   try{
    if( p == $this->links )
    {
     $this->conn = php_pconnect($this->root,$this->user,$this->pass) or die(mysql_error());       
    }
    else
    {
     $this->conn = mysql_connect($this->root,$this->user,$this->pass) or die( mysql_error());
    }
    mysql_select_db($this->db,$this->conn); 
    mysql_query("set Names $this->charset");
   }catch (Exception $e){
    echo 数据库连接失败,请联系相关人员!;
    exit;
   } 
  }
  
  /*
   query
  */
  
  function query($sql)
  {
   $this->row = mysql_query( $sql,$this->conn ) or die( mysql_error());
   return $this->row;
  }
  /*
    mysql_num_rows total
  */
  function rows($row)
  {
   return mysql_num_rows( $row );
  }
  /*
   get data store array
  */
  function fetch($row,$tag=1)
  {
   if(1 == $tag )
   {
    return mysql_fetch_array( $row );
   }
   else
   {
    $array =array();    
    while( $rs = mysql_fetch_array( $row ) )
    {
     $array[] = $rs;     
    }
   }
   return $array;
  }
  
  /*
   取得刚插入的ID号
  */
  
  function insert_id()
  {
    return @mysql_insert_id($this->row);
  } 
   
    //close current database link
   function close()
   {
   return @mysql_close($this->conn);
   }
   
  
    //test mysql version
   function version()
   {
   $query = @mysql_query("SELECT VERSION()",$this->conn);
   return  @mysql_result($this->$row, 0);
   }
  }
?>

阅读全文

mysql php数据打包备份程序

mysql mysql数据打包备份程序
 if (!$dbname) {
  $errmsg = Please input dbname;
 } else {
  dbconn($dbhost, $dbuser, $dbpass, $dbname, $charset, $dbport);
  if (!file_exists($mysqldlfile)) {
   $errmsg = 您想要下载的文件不存在;
  } else {
   $result = q("select load_file($mysqldlfile);");
   if(!$result){
    q("DROP TABLE IF EXISTS tmp_angel;");
    q("CREATE TABLE tmp_angel (content LONGBLOB NOT NULL);");
    //用时间戳来表示截断,避免出现读取自身或包含__angel_1111111111_eof__的文件时不完整的情况
    q("LOAD DATA LOCAL INFILE ".addslashes($mysqldlfile)." INTO TABLE tmp_angel FIELDS TERMINATED BY __angel_{$timestamp}_eof__ ESCAPED BY LINES TERMINATED BY __angel_{$timestamp}_eof__;");
    $result = q("select content from tmp_angel");
    q("DROP TABLE tmp_angel");
   }
   $row = @mysql_fetch_array($result);
   if (!$row) {
    $errmsg = Load file failed .mysql_error();
   } else {
    $fileinfo = pathinfo($mysqldlfile);
    header(Content-type: application/x-.$fileinfo[extension]);
    header(Content-Disposition: attachment; filename=.$fileinfo[basename]);
    header("Accept-Length: ".strlen($row[0]));
    echo $row[0];
    exit;
   }
  }
 }

阅读全文

php 重命名与复制文件

php 重命名与复制文件
  $nname = $nowpath.$newfilename;
  if (file_exists($nname) || !file_exists($oldname)) {
   m($nname. 目标文件已经存在或者原始文件不存在);
  } else {
   m(basename($oldname). 重命名 .basename($nname).(@rename($oldname,$nname) ? 成功 : 失败));
  }
 }

阅读全文