php 中常用的日期处理函数

// date_format2($rs['time'],'%y年%m月%d日%h时%m分%s秒');
function date_format2($string, $format='%b %e, %y', $default_date=null)
{
    if (substr(php教程_os,0,3) == 'win') {
           $_win_from = array ('%e',  '%t',       '%d');
           $_win_to   = array ('%#d', '%h:%m:%s', '%m/%d/%y');
           $format = str_replace($_win_from, $_win_to, $format);
    }
    if($string != '') {
        return strftime($format, smarty_make_timestamp($string));
    } elseif (isset($default_date) && $default_date != '') {
        return strftime($format, smarty_make_timestamp($default_date));
    } else {
        return;
    }
}
function smarty_make_timestamp($string){
    if(empty($string)) {
        $string = "now";
    }
    $time = strtotime($string);
    if (is_numeric($time) && $time != -1)
        return $time;
    if (preg_match('/^d{14}$/', $string)) {
        $time = mktime(substr($string,8,2),substr($string,10,2),substr($string,12,2),
               substr($string,4,2),substr($string,6,2),substr($string,0,4));

阅读全文

php中常用的函数集合

function getip() {
 if(getenv('http_client_ip') && strcasecmp(getenv('http_client_ip'), 'unknown')) {
  $onlineip = getenv('http_client_ip');
 } elseif(getenv('http_x_forwarded_for') && strcasecmp(getenv('http_x_forwarded_for'), 'unknown')) {
  $onlineip = getenv('http_x_forwarded_for');
 } elseif(getenv('remote_addr') && strcasecmp(getenv('remote_addr'), 'unknown')) {
  $onlineip = getenv('remote_addr');
 } elseif(isset($_server['remote_addr']) && $_server['remote_addr'] && strcasecmp($_server['remote_addr'], 'unknown')) {
  $onlineip = $_server['remote_addr'];
 }
 $onlineip = preg_replace("/^([d.]+).*/", "1", $onlineip);
 return $onlineip;
}

阅读全文

php采集防图片盗链方法

http_referer ,最简单的图片仿盗就是利用php教程的这个超级全局变量来实例了,但这个函数我们可以很简单的破解,原因我们可以写一个类是于浏览器的相关信息发送。代码如下。

阅读全文

php导入phpmyadmin生成 sql文件做法

分享一下 我所用的方法。只对php教程myadmin导出的sql文件有效

$dbfile="test.sql";
 $content=iconv("utf-8","gb2312",file_get_contents($dbfile));
 //获取创建的数据
 //去掉注释
 $content=preg_replace("/--.*n/iu","",$content);
 //替换前缀
 $content=str_replace("ct_",table_pre,$content);

阅读全文

sscanf定义和用法及分析

sscanf定义和用法及分析
sscanf() 函数根据指定的格式解析来自一个字符串的输入。

如果只向该函数传递两个参数,数据将以数组的形式返回。否则,如果传递了额外的参数,那么被解析的数据会存储在这些参数中。如果区分符的数目大于包含它们的变量的数目,则会发生错误。不过,如果区分符少于变量,则额外的变量包含 null。

阅读全文

php ini_get错误设置方法

php教程 ini_get错误设置方法

利用ini_set可以快速的修改php.ini配置设置哦,无需打开php.ini就可以了,特别是虚拟主机时你没有修改php.ini的权限时就会发现这个函数的作用了,下面看几个实例吧。
*/
//ini_set具有更改php.ini设置的功能。此函数接收两个参数:需要调整的配置变量名,以及变量的新值。

阅读全文

php 全局变量与静态变量分析详解

.静态变量
在函数内部static $a = 0;
注意:声明中用表达式的结果对其赋值会导致解析错误如static $a =3+3;(error)
静态变量仅在局部函数域中存在(函数内部),函数执行完之后,变量值不会丢失,可用于递归调用

阅读全文