两个php日期控制类

 更新时间:2016年11月25日 16:25  点击:2274
由于工作需要我找了二个时间日期控制,这个不用js只要php实现的,因为要带参考查询所以操作了操作,有需要的朋友可以参考一下哦,我自己用的是第二个,所以第二个己作了修改。

<?php教程

class Calendar
{
 var $month;
 var $year;

    function __construct($year,$month)
    {
     $this->year=$year;
  $this->month=$month;
 }

 function endday()
 {
  $daydate=date("d",mktime(0,0,0,$this->month,35,$this->year));
  $endday=35-$daydate;
  return $endday;
 }
 
 function oneday_week()
 {
  $oneday_week=date("w",mktime(0,0,0,$this->month,1,$this->year));
  return $oneday_week;
 }
 
 function title_link()
 {
  if(!isset($this->month) && !isset($this->year))
  {
   $this->year  = date("Y");
   $this->month = date("m");
        }
       
 
  $lastmonth=$this->month-1;
  $nextmonth=$this->month+1;
  $lastyear=$this->year;
  $nextyear=$this->year;

        if($this->month <= 1)
        {
         $lastmonth=12;
   $nextmonth=$this->month+1;
   $lastyear=$this->year-1;
   $nextyear=$this->year;
  }
        elseif ($this->month >= 12)
        {
         $lastmonth=$this->month-1;
         $nextmonth=1;
   $lastyear=$this->year;
   $nextyear=$this->year+1;
        }

        $str ="<td colspan='2'><div align='center'><a href=$PHP_SELF?year=".$lastyear."&month=".$lastmonth."&><<<</a></div></td>";
  $str.="<td colspan='3'><div align='center'>".$this->year."--".$this->month."</div></td>";
  $str.="<td colspan='2'><div align='center'><a href=$PHP_SELF?year=".$nextyear."&month=".$nextmonth."&>>>></a></div></td>";
  return $str;
 }
 
 
 function Show_Calendar()
 {
        echo "<table width='181' border=5><tr class='tr.title'>".$this->title_link()."</tr><tr>";
        $weekarray=array("日","一","二","三","四","五","六");
       
        for($k=0;$k<=6;$k++)
        {
         echo "<td><div align='center'>".$weekarray[$k]."</div></td>";
        }
        echo "</tr>";
       
        for($i=0;$i<=5;$i++)
        {
         echo "<tr>";
         for($j=1;$j<=7;$j++)
         {
    $math=( $j - $this->oneday_week() ) + 7 * $i;
   
          echo "<td><div align='center'>";
   
          if($math <= $this->endday() and $math>=1)
    {
         echo $math;
    }
   
         echo "</div></td>";
         }   
         echo "</tr>";    
        }
  echo "</table>";
         
 }
}

/*$calendar=new Calendar($_GET['year'],$_GET['month']);
//$calendar->month=$_GET['month'];
//$calendar->year=$_GET['year'];
$calendar->Show_Calendar();*/


//第二个

?>

实例二

<?php
header("content-type:text/html;charset=utf-8");
?>
<meta http-equiv="content-type" content="text/html;charset=utf-8">

<link href="statics/css教程/zhaoshang.css" rel="stylesheet" type="text/css">
<div class="rili">
<?php
if(!empty($_GET)){
    $year = isset($_GET['year'])?$_GET['year']:date('y');
    $month = isset($_GET['month'])?$_GET['month']:date('m');
 $day = isset($_GET['day'])?$_GET['day']:date('d');
}
if(empty($year)){
    $year = date('Y');
}
if(empty($month)){
    $month = date('m');
}

if(empty($month)){
    $days = date('d');
}

$start_weekday = date('w',mktime(0,0,0,$month,1,$year));
//echo $start_weekday;
$days = date('t',mktime(0,0,0,$month,1,$year));
//echo $days;
$week = array('日','一','二','三','四','五','六');
$i = 0;
$k = 1;
$j = 0;
echo '<table >';
echo '<tr><td colspan = 7 style ="text-align:center; width:250px; background:#d5e5f6; border-bottom:1px solid #333366;">'.$year.'年'.$month.'月'.'</td></tr>';
echo '<tr>';
for($i = 0;$i < 7;$i++){
    echo '<td>'.$week[$i].'</td>';
}
echo '</tr>';
echo '<tr>';
for($j = 0;$j < $start_weekday;$j++){
    echo '<td style="color:#f1f8fc;">'.$j.'</td>';
}
while($k <= $days){
    if($k == $day){
        echo '<td style="color:red"><a href="?year='.$year.'&month='.$month.'&day='.$k.'"><span style="color:red">'.$k.'</span></a></td>';
    }else{
        echo '<td><a href="?year='.$year.'&month='.$month.'&day='.$k.'">'.$k.'</a></td>';
    }
    if(($j+1) % 7 == 0){
        echo '</tr><tr>';
    }
    $j++;
    $k++;
}
while($j % 7 != 0){
    echo '<td style="color:#f1f8fc;">'.$j.'</td>';
    $j++;
}
echo '</tr>';

echo '<tr style="background:#d5e5f6;">';
echo "<td><a href=?".lastYear($year,$month).">".'<<'.'</a></td>';
echo "<td><a href=?".lastMonth($year,$month).">".'<'.'</a></td>';
echo '<td colspan = 3 style="width:105px;" >';
echo '<form name = "myform" method = "GET">';
echo '<select name = year  class="year">';
for($start_year = 1970;$start_year<2039;$start_year++){
 $selected='';
 if( $year== $start_year ) { $selected='selected'; }
 echo '<option value ='. $start_year.' '.$selected.'>'.$start_year.'</option>'." nt";
}
echo '</select>';
echo '<select name = month class="month">';
for($start_month = 1;$start_month<=12;$start_month++){
 $selected='';
 if( $month== $start_month ) { $selected='selected';}
 echo '<option value = '.$start_month.' '.$selected.'>'.$start_month.'</option>'." nt";
}
echo '</select>';
/*echo '月';*/
/*echo '<input type = "submit" name = "search" value = "查询">';*/
echo '</form>';
echo '</td>';
echo "<td><a href=?".nextYear($year,$month).">".'>>'.'</a></td>';
echo "<td><a href=?".nextMonth($year,$month).">".'>'.'</a></td>';
echo '</tr>';
echo '</table>';

function lastYear($year,$month){
 $year = $year-1;
 return "year=$year&month=$month";
}
function lastMonth($year,$month){
 if($month == 1){
  $year = $year -1;
  $month = 12;
 }else{
  $month--;
 }
 return "year=$year&month=$month";
}
function nextYear($year,$month){
 $year = $year+1;
 return "year=$year&month=$month";
}
function nextMonth($year,$month){
 if($month == 12){
  $year = $year +1;
  $month = 1;
 }else {
  $month++;
 }
 return "year=$year&month=$month";
}

?>
</div>
 

这个程序是利用php+ajax+jquery 实现的一个仿baidu智能提示的效果,有需要的朋友可以下载测试哦。

先来看看效果

代码如下

index.html文件,保保存成index.htm

 代码如下 复制代码

<!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=utf-8" />
<title>Ajax Auto Suggest</title>

<script type="text/网页特效" src="jquery-1.2.1.pack.js"></script>
<script type="text/javascript">
 function lookup(inputString) {
  if(inputString.length == 0) {
   // Hide the suggestion box.
   $('#suggestions').hide();
  } else {
   $.post("rpc.php", {queryString: ""+inputString+""}, function(data){
    if(data.length >0) {
     $('#suggestions').show();
     $('#autoSuggestionsList').html(data);
    }
   });
  }
 } // lookup
 
 function fill(thisValue) {
  $('#inputString').val(thisValue);
  setTimeout("$('#suggestions').hide();", 200);
 }
</script>

<style type="text/css教程">
 body {
  font-family: Helvetica;
  font-size: 11px;
  color: #000;
 }
 
 h3 {
  margin: 0px;
  padding: 0px; 
 }

 .suggestionsBox {
  position: relative;
  left: 30px;
  margin: 10px 0px 0px 0px;
  width: 200px;
  background-color: #212427;
  -moz-border-radius: 7px;
  -webkit-border-radius: 7px;
  border: 2px solid #000; 
  color: #fff;
 }
 
 .suggestionList {
  margin: 0px;
  padding: 0px;
 }
 
 .suggestionList li {
  
  margin: 0px 0px 3px 0px;
  padding: 3px;
  cursor: pointer;
 }
 
 .suggestionList li:hover {
  background-color: #659CD8;
 }
</style>

</head>

<body>


 <div>
  <form>
   <div>
    Type your county:
    <br />
    <input type="text" size="30" value="" id="inputString" onkeyup="lookup(this.value);" onblur="fill();" />
   </div>
   
   <div class="suggestionsBox" id="suggestions" style="display: none;">
    <img src="upArrow.png" style="position: relative; top: -12px; left: 30px;" alt="upArrow" />
    <div class="suggestionList" id="autoSuggestionsList">
     &nbsp;
    </div>
   </div>
  </form>
 </div>

</body>
</html>

php文件

 代码如下 复制代码

<?php
 
    mysql教程_connect('localhost', 'root' ,'root');
 mysql_select_db("autoComplete"); 
 
 $queryString = $_POST['queryString'];
   
   if(strlen($queryString) >0) {
    $sql= "SELECT value FROM countries WHERE value LIKE '".$queryString."%' LIMIT 10";
    $query = mysql_query($sql);
    while ($result = mysql_fetch_array($query,MYSQL_BOTH)){    
     $value=$result['value'];
     echo '<li onClick="fill(''.$value.'');">'.$value.'</li>';
    }

   }
 
?>

sql.sql把这里复制保存到你的数据库教程

 代码如下 复制代码

-- phpMyAdmin SQL Dump
-- version 3.3.5
-- http://www.phpmyadmin.net
--
-- 主机: localhost
-- 生成日期: 2010 年 12 月 09 日 02:36
-- 服务器版本: 5.0.22
-- PHP 版本: 5.2.14

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- 数据库: `autoComplete`
--

-- --------------------------------------------------------

--
-- 表的结构 `countries`
--

CREATE TABLE IF NOT EXISTS `countries` (
  `id` int(6) NOT NULL auto_increment,
  `value` varchar(250) NOT NULL default '',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=243 ;

--
-- 转存表中的数据 `countries`
--

INSERT INTO `countries` (`id`, `value`) VALUES
(1, 'Afghanistan'),
(2, 'Aringland Islands'),
(3, 'Albania'),
(4, 'Algeria'),
(5, 'American Samoa'),
(6, 'Andorra'),
(7, 'Angola'),
(8, 'Anguilla'),
(9, 'Antarctica'),
(10, 'Antigua and Barbuda'),
(11, 'Argentina'),
(12, 'Armenia'),
(13, 'Aruba'),
(14, 'Australia'),
(15, 'Austria'),
(16, 'Azerbaijan'),
(17, 'Bahamas'),
(18, 'Bahrain'),
(19, 'Bangladesh'),
(20, 'Barbados'),
(21, 'Belarus'),
(22, 'Belgium'),
(23, 'Belize'),
(24, 'Benin'),
(25, 'Bermuda'),
(26, 'Bhutan'),
(27, 'Bolivia'),
(28, 'Bosnia and Herzegovina'),
(29, 'Botswana'),
(30, 'Bouvet Island'),
(31, 'Brazil'),
(32, 'British Indian Ocean territory'),
(33, 'Brunei Darussalam'),
(34, 'Bulgaria'),
(35, 'Burkina Faso'),
(36, 'Burundi'),
(37, 'Cambodia'),
(38, 'Cameroon'),
(39, 'Canada'),
(40, 'Cape Verde'),
(41, 'Cayman Islands'),
(42, 'Central African Republic'),
(43, 'Chad'),
(44, 'Chile'),
(45, 'China'),
(46, 'Christmas Island'),
(47, 'Cocos (Keeling) Islands'),
(48, 'Colombia'),
(49, 'Comoros'),
(50, 'Congo'),
(51, 'Congo'),
(52, ' Democratic Republic'),
(53, 'Cook Islands'),
(54, 'Costa Rica'),
(55, 'Ivory Coast (Ivory Coast)'),
(56, 'Croatia (Hrvatska)'),
(57, 'Cuba'),
(58, 'Cyprus'),
(59, 'Czech Republic'),
(60, 'Denmark'),
(61, 'Djibouti'),
(62, 'Dominica'),
(63, 'Dominican Republic'),
(64, 'East Timor'),
(65, 'Ecuador'),
(66, 'Egypt'),
(67, 'El Salvador'),
(68, 'Equatorial Guinea'),
(69, 'Eritrea'),
(70, 'Estonia'),
(71, 'Ethiopia'),
(72, 'Falkland Islands'),
(73, 'Faroe Islands'),
(74, 'Fiji'),
(75, 'Finland'),
(76, 'France'),
(77, 'French Guiana'),
(78, 'French Polynesia'),
(79, 'French Southern Territories'),
(80, 'Gabon'),
(81, 'Gambia'),
(82, 'Georgia'),
(83, 'Germany'),
(84, 'Ghana'),
(85, 'Gibraltar'),
(86, 'Greece'),
(87, 'Greenland'),
(88, 'Grenada'),
(89, 'Guadeloupe'),
(90, 'Guam'),
(91, 'Guatemala'),
(92, 'Guinea'),
(93, 'Guinea-Bissau'),
(94, 'Guyana'),
(95, 'Haiti'),
(96, 'Heard and McDonald Islands'),
(97, 'Honduras'),
(98, 'Hong Kong'),
(99, 'Hungary'),
(100, 'Iceland'),
(101, 'India'),
(102, 'Indonesia'),
(103, 'Iran'),
(104, 'Iraq'),
(105, 'Ireland'),
(106, 'Israel'),
(107, 'Italy'),
(108, 'Jamaica'),
(109, 'Japan'),
(110, 'Jordan'),
(111, 'Kazakhstan'),
(112, 'Kenya'),
(113, 'Kiribati'),
(114, 'Korea (north)'),
(115, 'Korea (south)'),
(116, 'Kuwait'),
(117, 'Kyrgyzstan'),
(118, 'Lao People''s Democratic Republic'),
(119, 'Latvia'),
(120, 'Lebanon'),
(121, 'Lesotho'),
(122, 'Liberia'),
(123, 'Libyan Arab Jamahiriya'),
(124, 'Liechtenstein'),
(125, 'Lithuania'),
(126, 'Luxembourg'),
(127, 'Macao'),
(128, 'Macedonia'),
(129, 'Madagascar'),
(130, 'Malawi'),
(131, 'Malaysia'),
(132, 'Maldives'),
(133, 'Mali'),
(134, 'Malta'),
(135, 'Marshall Islands'),
(136, 'Martinique'),
(137, 'Mauritania'),
(138, 'Mauritius'),
(139, 'Mayotte'),
(140, 'Mexico'),
(141, 'Micronesia'),
(142, 'Moldova'),
(143, 'Monaco'),
(144, 'Mongolia'),
(145, 'Montserrat'),
(146, 'Morocco'),
(147, 'Mozambique'),
(148, 'Myanmar'),
(149, 'Namibia'),
(150, 'Nauru'),
(151, 'Nepal'),
(152, 'Netherlands'),
(153, 'Netherlands Antilles'),
(154, 'New Caledonia'),
(155, 'New Zealand'),
(156, 'Nicaragua'),
(157, 'Niger'),
(158, 'Nigeria'),
(159, 'Niue'),
(160, 'Norfolk Island'),
(161, 'Northern Mariana Islands'),
(162, 'Norway'),
(163, 'Oman'),
(164, 'Pakistan'),
(165, 'Palau'),
(166, 'Palestinian Territories'),
(167, 'Panama'),
(168, 'Papua New Guinea'),
(169, 'Paraguay'),
(170, 'Peru'),
(171, 'Philippines'),
(172, 'Pitcairn'),
(173, 'Poland'),
(174, 'Portugal'),
(175, 'Puerto Rico'),
(176, 'Qatar'),
(177, 'Runion'),
(178, 'Romania'),
(179, 'Russian Federation'),
(180, 'Rwanda'),
(181, 'Saint Helena'),
(182, 'Saint Kitts and Nevis'),
(183, 'Saint Lucia'),
(184, 'Saint Pierre and Miquelon'),
(185, 'Saint Vincent and the Grenadines'),
(186, 'Samoa'),
(187, 'San Marino'),
(188, 'Sao Tome and Principe'),
(189, 'Saudi Arabia'),
(190, 'Senegal'),
(191, 'Serbia and Montenegro'),
(192, 'Seychelles'),
(193, 'Sierra Leone'),
(194, 'Singapore'),
(195, 'Slovakia'),
(196, 'Slovenia'),
(197, 'Solomon Islands'),
(198, 'Somalia'),
(199, 'South Africa'),
(200, 'South Georgia and the South Sandwich Islands'),
(201, 'Spain'),
(202, 'Sri Lanka'),
(203, 'Sudan'),
(204, 'Suriname'),
(205, 'Svalbard and Jan Mayen Islands'),
(206, 'Swaziland'),
(207, 'Sweden'),
(208, 'Switzerland'),
(209, 'Syria'),
(210, 'Taiwan'),
(211, 'Tajikistan'),
(212, 'Tanzania'),
(213, 'Thailand'),
(214, 'Togo'),
(215, 'Tokelau'),
(216, 'Tonga'),
(217, 'Trinidad and Tobago'),
(218, 'Tunisia'),
(219, 'Turkey'),
(220, 'Turkmenistan'),
(221, 'Turks and Caicos Islands'),
(222, 'Tuvalu'),
(223, 'Uganda'),
(224, 'Ukraine'),
(225, 'United Arab Emirates'),
(226, 'United Kingdom'),
(227, 'United States of America'),
(228, 'Uruguay'),
(229, 'Uzbekistan'),
(230, 'Vanuatu'),
(231, 'Vatican City'),
(232, 'Venezuela'),
(233, 'Vietnam'),
(234, 'Virgin Islands (British)'),
(235, 'Virgin Islands (US)'),
(236, 'Wallis and Futuna Islands'),
(237, 'Western Sahara'),
(238, 'Yemen'),
(239, 'Zaire'),
(240, 'Zambia'),
(241, 'Zimbabwe');

 

注:里面有个jquery文件没有放上来,大家可以到http://down.111cn.net下载或者到百度搜索

<?php教程
/**

* 转化 为 /
*
* @param string $path 路径
* @return string 路径
*/
function dir_path($path) {
 $path = str_replace('\', '/', $path);
 if(substr($path, -1) != '/') $path = $path.'/';
 return $path;
}
/**
* 创建目录
*
* @param string $path 路径
* @param string $mode 属性
* @return string 如果已经存在则返回true,否则为flase
*/
function dir_create($path, $mode = 0777) {
 if(is_dir($path)) return TRUE;
 $ftp_enable = 0;
 $path = dir_path($path);
 $temp = explode('/', $path);
 $cur_dir = '';
 $max = count($temp) - 1;
 for($i=0; $i<$max; $i++) {
  $cur_dir .= $temp[$i].'/';
  if (@is_dir($cur_dir)) continue;
  @mkdir($cur_dir, 0777,true);
  @chmod($cur_dir, 0777);
 }
 return is_dir($path);
}
/**
* 拷贝目录及下面所有文件
*
* @param string $fromdir 原路径
* @param string $todir  目标路径
* @return string 如果目标路径不存在则返回false,否则为true
*/
function dir_copy($fromdir, $todir) {
 $fromdir = dir_path($fromdir);
 $todir = dir_path($todir);
 if (!is_dir($fromdir)) return FALSE;
 if (!is_dir($todir)) dir_create($todir);
 $list = glob($fromdir.'*');
 if (!empty($list)) {
  foreach($list as $v) {
   $path = $todir.basename($v);
   if(is_dir($v)) {
    dir_copy($v, $path);
   } else {
    copy($v, $path);
    @chmod($path, 0777);
   }
  }
 }
    return TRUE;
}
/**
* 转换目录下面的所有文件编码格式
*
* @param string $in_charset  原字符集
* @param string $out_charset 目标字符集
* @param string $dir   目录地址
* @param string $fileexts  转换的文件格式
* @return string 如果原字符集和目标字符集相同则返回false,否则为true
*/
function dir_iconv($in_charset, $out_charset, $dir, $fileexts = 'php|html|htm|shtml|shtm|js|txt|xml') {
 if($in_charset == $out_charset) return false;
 $list = dir_list($dir);
 foreach($list as $v) {
  if (preg_match("/.($fileexts)/i", $v) && is_file($v)){
   file_put_contents($v, iconv($in_charset, $out_charset, file_get_contents($v)));
  }
 }
 return true;
}
/**
* 列出目录下所有文件
*
* @param string $path  路径
* @param string $exts  扩展名
* @param array $list  增加的文件列表
* @return array 所有满足条件的文件
*/
function dir_list($path, $exts = '', $list= array()) {
 $path = dir_path($path);
 $files = glob($path.'*');
 foreach($files as $v) {
  $fileext = fileext($v);
  if (!$exts || preg_match("/.($exts)/i", $v)) {
   $list[] = $v;
   if (is_dir($v)) {
    $list = dir_list($v, $exts, $list);
   }
  }
 }
 return $list;
}
/**
* 设置目录下面的所有文件的访问和修改时间
*
* @param string $path  路径
* @param int  $mtime  修改时间
* @param int  $atime  访问时间
* @return array 不是目录时返回false,否则返回 true
*/
function dir_touch($path, $mtime = TIME, $atime = TIME) {
 if (!is_dir($path)) return false;
 $path = dir_path($path);
 if (!is_dir($path)) touch($path, $mtime, $atime);
 $files = glob($path.'*');
 foreach($files as $v) {
  is_dir($v) ? dir_touch($v, $mtime, $atime) : touch($v, $mtime, $atime);
 }
 return true;
}
/**
* 目录列表
*
* @param string $dir  路径
* @param int  $parentid 父id
* @param array $dirs  传入的目录
* @return array 返回目录列表
*/
function dir_tree($dir, $parentid = 0, $dirs = array()) {
 global $id;
 if ($parentid == 0) $id = 0;
 $list = glob($dir.'*');
 foreach($list as $v) {
  if (is_dir($v)) {
            $id++;
   $dirs[$id] = array('id'=>$id,'parentid'=>$parentid, 'name'=>basename($v), 'dir'=>$v.'/');
   $dirs = dir_tree($v.'/', $id, $dirs);
  }
 }
 return $dirs;
}

/**
* 删除目录及目录下面的所有文件
*
* @param string $dir  路径
* @return bool 如果成功则返回 TRUE,失败则返回 FALSE
*/
function dir_delete($dir) {
 $dir = dir_path($dir);
 if (!is_dir($dir)) return FALSE;
 $list = glob($dir.'*');
 foreach($list as $v) {
  is_dir($v) ? dir_delete($v) : @unlink($v);
 }
    return @rmdir($dir);
}

?>

for循环只对数字索引有限;for和foreach遍历结束后不需要对数据进行reset()操作即可供下次遍历,而each方法则需要

<?php教程
//a
$arr=array('a'=>'abc','b'=>123,'c'=>true);
//b
//$arr=range('a','d');

//1   
for($i=0;$i<sizeof($arr);$i++)
    echo $arr[$i].', ';
echo '<br />';

//2
foreach($arr as $key)
    echo "$key, ";
echo '<br />';

//3
foreach($arr as $key=>$val)
    echo "$key-$val, ";
echo '<br />';

//4
reset($arr);
while($item=each($arr)){
    echo $item['key'].'-'.$item['value'].', ';
}
echo '<br />';

//5
reset($arr);
while(list($key,$val)=each($arr)){
    echo "$key-$val, ";
}
echo '<br />';
?>使用语句a $arr=array('a'=>'abc','b'=>123,'c'=>true); 对$arr进行初始化得到数字索引数组,输出如下:

, , ,
abc, 123, 1,
a-abc, b-123, c-1,
a-abc, b-123, c-1,
a-abc, b-123, c-1, 使用语句b $arr=range('a','d'); 对$arr进行初始化得到关联数组,输出如下:

a, b, c, d,
a, b, c, d,
0-a, 1-b, 2-c, 3-d,
0-a, 1-b, 2-c, 3-d,
0-a, 1-b, 2-c, 3-d,

经过反复多次测试,结果表明,对于遍历同样一个数组,foreach速度最快,最慢的则是while。foreach比while大约快20% ~ 30%左右。随后再把数组下标增加到500000、5000000测试结果也一样。但从原理上来看,foreach是对数组副本进行操作(通过拷贝数组),而while则通过移动数组内部指标进行操作,一般逻辑下认为,while应该比foreach快(因为foreach在开始执行的时候首先把数组复制进去,而while直接移动内部指标。),但结果刚刚相反。原因应该是,foreach是PHP内部实现,而while是通用的循环结构

 

今天一个客户说它的magento 1.6后台无法登录,找了好久才找到解决办法 ,这是从网上找到,希望同样出现这种问题朋友能够参考一下。

magento 1.4.x stable has a problem on the login procedure on localhost.
you need to change in app/code/core/Mage/Core/Model/Session/Abstract/Varien.php教程


// session cookie params
     

   $cookieParams = array(
            'lifetime' => $cookie->getLifetime(),
            'path'     => $cookie->getPath(),
            'domain'   => $cookie->getConfigDomain(),
            'secure'   => $cookie->isSecure(),
            'httponly' => $cookie->getHttponly()
         );

         if (!$cookieParams['httponly']) {
            unset($cookieParams['httponly']);
             if (!$cookieParams['secure']) {
                unset($cookieParams['secure']);
                 if (!$cookieParams['domain']) {
                    unset($cookieParams['domain']);
                }
             }
         }

        if (isset($cookieParams['domain'])) {
             $cookieParams['domain'] = $cookie->getDomain();
        }with
// session cookie params
        $cookieParams = array(
            'lifetime' => $cookie->getLifetime(),
            'path'     => $cookie->getPath(),
           // 'domain'    => $cookie->getConfigDomain(),
            // 'secure'    => $cookie->isSecure(),
            // 'httponly' => $cookie->getHttponly()
        );
/*
         if (!$cookieParams['httponly']) {
             unset($cookieParams['httponly']);
             if (!$cookieParams['secure']) {
                 unset($cookieParams['secure']);
                 if (!$cookieParams['domain']) {
                     unset($cookieParams['domain']);
                 }
             }
         }

         if (isset($cookieParams['domain'])) {
             $cookieParams['domain'] = $cookie->getDomain();
         }
*/

[!--infotagslink--]

相关文章

  • 源码分析系列之json_encode()如何转化一个对象

    这篇文章主要介绍了源码分析系列之json_encode()如何转化一个对象,对json_encode()感兴趣的同学,可以参考下...2021-04-22
  • php中去除文字内容中所有html代码

    PHP去除html、css样式、js格式的方法很多,但发现,它们基本都有一个弊端:空格往往清除不了 经过不断的研究,最终找到了一个理想的去除html包括空格css样式、js 的PHP函数。...2013-08-02
  • index.php怎么打开?如何打开index.php?

    index.php怎么打开?初学者可能不知道如何打开index.php,不会的同学可以参考一下本篇教程 打开编辑:右键->打开方式->经文本方式打开打开运行:首先你要有个支持运行PH...2017-07-06
  • JS日期加减,日期运算代码

    一、日期减去天数等于第二个日期function cc(dd,dadd){//可以加上错误处理var a = new Date(dd)a = a.valueOf()a = a - dadd * 24 * 60 * 60 * 1000a = new Date(a)alert(a.getFullYear() + "年" + (a.getMonth() +...2015-11-08
  • PostgreSQL 字符串处理与日期处理操作

    这篇文章主要介绍了PostgreSQL 字符串处理与日期处理操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-02-01
  • php计算两个日期相差天数的方法

    本文实例讲述了php计算两个日期相差天数的方法。...2015-03-15
  • vue开发之moment的介绍与使用

    moment是一款多语言支持的日期处理类库, 在vue中如何使用呢?这篇文章主要给大家介绍了关于vue之moment使用的相关资料,需要的朋友可以参考下...2021-05-13
  • 非常全面的php日期时间运算汇总

    实例讲解之前,先来介绍几个核心函数: mktime 函数 mktime() 函数返回一个日期的 Unix 时间戳。 参数总是表示 GMT 日期,因此 is_dst 对结果没有影响。 参数可以从右到左依次空着,空着的参数会被设为相应的当前 GMT 值。...2015-11-08
  • PHP中func_get_args(),func_get_arg(),func_num_args()的区别

    复制代码 代码如下:<?php function jb51(){ print_r(func_get_args()); echo "<br>"; echo func_get_arg(1); echo "<br>"; echo func_num_args(); } jb51("www","j...2013-10-04
  • PHP编程 SSO详细介绍及简单实例

    这篇文章主要介绍了PHP编程 SSO详细介绍及简单实例的相关资料,这里介绍了三种模式跨子域单点登陆、完全跨单点域登陆、站群共享身份认证,需要的朋友可以参考下...2017-01-25
  • C#实现将字符串转换成日期格式的方法

    这篇文章主要介绍了C#实现将字符串转换成日期格式的方法,涉及C#操作时间及字符串的相关技巧,非常简单实用,需要的朋友可以参考下...2020-06-25
  • PHP实现创建以太坊钱包转账等功能

    这篇文章主要介绍了PHP实现创建以太坊钱包转账等功能,对以太坊感兴趣的同学,可以参考下...2021-04-20
  • php根据日期或时间戳获取星座信息和生肖等信息

    分享一个利用php根据日期或时间戳获取相应的干支纪年,生肖和星座信息的函数方法,具体函数代码以及使用方法如下: /** 判断干支、生肖和星座 */ function birthext($birth){ if(strstr($birth,'-')===false&&strlen($bi...2015-10-21
  • php微信公众账号开发之五个坑(二)

    这篇文章主要为大家详细介绍了php微信公众账号开发之五个坑,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2016-10-02
  • java8时间 yyyyMMddHHmmss格式转为日期的代码

    这篇文章主要介绍了java8时间 yyyyMMddHHmmss格式转为日期的代码,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-09-17
  • ThinkPHP使用心得分享-ThinkPHP + Ajax 实现2级联动下拉菜单

    首先是数据库的设计。分类表叫cate.我做的是分类数据的二级联动,数据需要的字段有:id,name(中文名),pid(父id). 父id的设置: 若数据没有上一级,则父id为0,若有上级,则父id为上一级的id。数据库有内容后,就可以开始写代码,进...2014-05-31
  • PHP如何通过date() 函数格式化显示时间

    这篇文章主要介绍了PHP如何通过date() 函数格式化显示时间,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-11-13
  • PHP+jQuery+Ajax实现多图片上传效果

    今天我给大家分享的是在不刷新页面的前提下,使用PHP+jQuery+Ajax实现多图片上传的效果。用户只需要点击选择要上传的图片,然后图片自动上传到服务器上并展示在页面上。...2015-03-15
  • C#判断日期是否到期的方法

    这篇文章主要介绍了C#判断日期是否到期的方法,是C#程序设计中非常实用的技巧,需要的朋友可以参考下...2020-06-25
  • sql通过日期判断年龄函数的示例代码

    这篇文章主要介绍了sql通过日期判断年龄函数,本文通过示例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2021-07-16