• PHP常用


    php.ini文件配置

    时间配置PRC中国

    date.timezone = PRC 


    文件上传
    file_uploads = On //支持http上传
    upload_tmp_dir = //临时文件保存路径
    upload_max_filesize = 2M //上传的大小限制
    post_max_size = 10M //post提交的大小限制
    max_file_uploads = 20 //允许一次上传的最大文件数

    XDEBUG设置,函数嵌套循环次数:

    报错内容:Fatal error: Maximum function nesting level of '100' reached, aborting!

    解决办法

    查找xdebug 找到zend_extension = “D:/wamp/bin/php/php5.3.13/zend_ext/php_xdebug-2.2.0-5.3-vc9-x86_64.dll”  这句在前面加;注视掉,在后面加上

    xdebug.max_nesting_level = 500


    乱码处理

    防止乱码 先把utf-8转换成gb2312,copy完成后再转回utf-8
    $newFile = iconv("utf-8","gb2312", $newFile);


    输出字体颜色

    echo '<span style="color:#F00" >字体为红色</span>';


    格式化日期为时间戳

    strtotime('2013-03-18') 

    $startTime='2013-03-18';

    $endTime='2013-03-20'

    $days=ceil((strtotime($endTime)-strtotime($startTime))/86400)+1 //求相差几天 60s*60min*24H

     $shorStartTime=str_replace('-', '.', substr($startTime, 5)); //展示方式为03.18

     1 <?php
     2 //PHP计算两个时间差的方法 
     3 $startdate="2010-12-11 11:40:00";
     4 $enddate="2012-12-12 11:45:09";
     5 $date=floor((strtotime($enddate)-strtotime($startdate))/86400);
     6 $hour=floor((strtotime($enddate)-strtotime($startdate))%86400/3600);
     7 $minute=floor((strtotime($enddate)-strtotime($startdate))%86400/60);
     8 $second=floor((strtotime($enddate)-strtotime($startdate))%86400%60);
     9 echo $date."天<br>";
    10 echo $hour."小时<br>";
    11 echo $minute."分钟<br>";
    12 echo $second."秒<br>";
    13 ?>
     1 <?php
     2 /**
     3  * 时间差计算
     4  *
     5  * @param Timestamp $time
     6  * @return String Time Elapsed
     7  * @author Shelley Shyan
     8  * @copyright http://phparch.cn (Professional PHP Architecture)
     9  */
    10 function time2Units ($time)
    11 {
    12    $year   = floor($time / 60 / 60 / 24 / 365);
    13    $time  -= $year * 60 * 60 * 24 * 365;
    14    $month  = floor($time / 60 / 60 / 24 / 30);
    15    $time  -= $month * 60 * 60 * 24 * 30;
    16    $week   = floor($time / 60 / 60 / 24 / 7);
    17    $time  -= $week * 60 * 60 * 24 * 7;
    18    $day    = floor($time / 60 / 60 / 24);
    19    $time  -= $day * 60 * 60 * 24;
    20    $hour   = floor($time / 60 / 60);
    21    $time  -= $hour * 60 * 60;
    22    $minute = floor($time / 60);
    23    $time  -= $minute * 60;
    24    $second = $time;
    25    $elapse = '';
    26 
    27    $unitArr = array('年'  =>'year', '个月'=>'month',  '周'=>'week', '天'=>'day',
    28                     '小时'=>'hour', '分钟'=>'minute', '秒'=>'second'
    29                     );
    30 
    31    foreach ( $unitArr as $cn => $u )
    32    {
    33        if ( $$u > 0 )
    34        {
    35            $elapse = $$u . $cn;
    36            break;
    37        }
    38    }
    39 
    40    return $elapse;
    41 }
    42 
    43 $past = 2052345678; // Some timestamp in the past
    44 $now  = time();     // Current timestamp
    45 $diff = $now - $past;
    46 
    47 echo '发表于' . time2Units($diff) . '前';
    48 ?>

     php字符串处理

    substr_count($str,'|'); //计算某个字符在字符串中出现的次数
    explode('|', $str, 2); //把一个字符以某个字符分割成几段
    举例:7/3
    整数部分:intval(floor(7/3))
    余数部分:7%3
  • 相关阅读:
    java源码之HashMap和HashTable的异同
    java源码之HashMap
    进制转换
    java基本数据类型及其包装类
    java实例化对象的五种方法
    20 栈的压入、弹出序列
    19 包含min函数的栈
    18 顺时针打印矩阵(记忆,常忘记)
    16 树的子结构(这题多复习)
    15合并两个排序的链表
  • 原文地址:https://www.cnblogs.com/blueskycc/p/4348467.html
Copyright © 2020-2023  润新知