【javascript】JS-向当前url追加参数


   

  var cate_id = 3;
  //当前url 追加参数
  var newurl = updateQueryStringParameter(window.location.href, 'cate_id', cate_id);
  window.location.href = newurl;

    //当前url 追加参数
    function updateQueryStringParameter(uri, key, value) {
        if(!value) {
            return uri;
        }
        var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
        var separator = uri.indexOf('?') !== -1 ? "&" : "?";
        if (uri.match(re)) {
            return uri.replace(re, '$1' + key + "=" + value + '$2');
        }
        else {
            return uri + separator + key + "=" + value;
        }
    }


【PHP】php实现的无限极分类


上代码

<?php

$rows = array(
  array(
    'id' => 1,
    'name' => 'dev',
    'parentid' => 0
  ),

  array(
    'id' => 2,
    'name' => 'php',
    'parentid' => 1
  ),

  array(
    'id' => 3,
    'name' => 'thinkphp',
    'parentid' => 2

  ),
  array(
    'id' => 4,
    'name' => 'life',
    'parentid' => 0
  ),

  array(
    'id' => 5,
    'name' => 'pdo',
    'parentid' => 2
  ),

  array(
    'id' => 6,
    'name' => 'pdo-mysql',
    'parentid' => 5
  ),

  array(
    'id' => 7,
    'name' => 'java',
    'parentid' => 1
  )
);


$tree=build_tree($arr,0);
print_r($tree);


function build_tree($rows,$root_id){
  $childs=findChild($rows,$root_id);
  if(empty($childs)){
    return null;
  }
  foreach ($childs as $k => $v){
    $rescurTree=build_tree($rows,$v['id']);
    if( null !=  $rescurTree){ 
      $childs[$k]['childs']=$rescurTree;
    }
  }
  return $childs;
}


function findChild($arr,$id){
  $childs=array();
   foreach ($arr as $k => $v){
     if($v['parentid']== $id){
       $childs[]=$v;
     }
  }
  return $childs;
}


?>


【PHP】判断一个字符串是否属于序列化后的数据


function is_serialized( $data ) {
     $data = trim( $data );
     if ( 'N;' == $data )
         return true;
     if ( !preg_match( '/^([adObis]):/', $data, $badions ) )
         return false;
     switch ( $badions[1] ) {
         case 'a' :
         case 'O' :
         case 's' :
             if ( preg_match( "/^{$badions[1]}:[0-9]+:.*[;}]\$/s", $data ) )
                 return true;
             break;
         case 'b' :
         case 'i' :
         case 'd' :
             if ( preg_match( "/^{$badions[1]}:[0-9.E-]+;\$/", $data ) )
                 return true;
             break;
     }
     return false;
 }