首页 > php代码

php树型菜单类

原理简单,学过数据结构的一看就明白是什么道理了。不过今天在使用时数据中出现了子节点id(71)小于父节点id(104).导致部分子节点没被存储入数组
修改了一下

阅读全文

php小型数据库(不用mysql做网站)

php教程小型数据库教程(不用mysql教程做网站) include 'pdbm.php'; $timestart = explode(' ', microtime()); $timestart = $timestart[0] + $timestart[1]; $pdbm = new pdbm('test'); $pdbm->open(pdbm_creat | pdbm_rewd); for ($i = 0; $i < 100000; $i++) {     $pdbm->insert("key{$i}",...
阅读全文

php curl post数据的问题

 今天在做一个api增量的功能的时候出现了一个特别奇怪的问题。我用curl 想tomcat post数据的时候,tomcat竟然报错,所我post的数据没有正确或得。但是,我用curl post给我自己写的一个页面,就可以在$_post数组中获得数据。为什么会出现这种问题那?原因是在构建post 数据的数量出现问题。。。1 function api_notice_increment($url, $data) 2 { 3 $ch = curl_init(); 4 curl_setopt($ch, curlopt_header,0); 5 c...
阅读全文

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 中常用的日期处理函数

// 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));

阅读全文