海运的博客

从文本导入数据到数据库

发布时间:December 9, 2013 // 分类:PHP,数据库 // No Comments

文本多列以,分隔,导入到指定字段:

load data local infile "file.txt" into table db.table FIELDS TERMINATED BY ',' (name,address);
load data local infile "file.txt" into table db.table (name,address) FIELDS TERMINATED BY ',';
update db.table SET aaa = 'test'; 

也可使用PHP以数组的方式逐行插入,自定义方便。

<?php  
   $hostname="localhost";
   $username="root";
   $password="passwd";  
   $dbname="dbname";
   mysql_connect($hostname,$username,$password);
   mysql_select_db("$dbname");
   $mydate=file("/root/m.txt");
   $n=count($mydate);
   for($i=0;$i<$n;$i++){
      $date=explode(",",$mydate[$i]);
      $str="insert into table (name,address) values ('$date[0]','$date[1]')";
      mysql_query($str);
   }
   mysql_close();
   echo "ok!";
?> 

PHP数组实现简单循环队列

发布时间:December 8, 2013 // 分类:PHP // No Comments

<?php
   function queue() {
      static $queue =  array(a,b,c,d);
      $a = array_shift($queue);
      $queue[] = $a;
      print_r($queue);
      echo $a;
   }
   queue();
   queue();
   queue();
   queue();
?>

其它可用到的函数:

array_unshift() 在数组开头插入元素
array_push() 在数组尾部插入数据
array_pop() 删除数组尾部数据

解密函数

发布时间:December 8, 2013 // 分类:PHP // No Comments

<?php
   function jspassword($p, $vc, $vt) {
      $p = strtoupper(md5($p));
      for ($i = 0; $i < strlen($p); $i = $i + 2) {
         $temp .= '\x' . substr($p, $i, 2);
      }
      return strtoupper(md5(strtoupper(md5(hex2asc($temp) . hex2asc($vt))) . $vc));
   } 
   function hex2asc($str) {
      $str = join('', explode('\x', $str));
      for ($i = 0;$i < strlen($str);$i += 2) {
         $data.= chr(hexdec(substr($str, $i, 2)));
      }
      return $data;
   } 

   function getGTK($skey){
      $hash = 5381;
      for($i=0;$i<strlen($skey);++$i){
         $hash += ($hash << 5) + utf8_unicode($skey[$i]);
      }
      return $hash & 0x7fffffff;
   }

   function utf8_unicode($c) {                 
      switch(strlen($c)) {                 
         case 1:                 
         return ord($c);                 
         case 2:                 
         $n = (ord($c[0]) & 0x3f) << 6;                 
         $n += ord($c[1]) & 0x3f;                 
         return $n;                 
         case 3:                 
         $n = (ord($c[0]) & 0x1f) << 12;                 
         $n += (ord($c[1]) & 0x3f) << 6;                 
         $n += ord($c[2]) & 0x3f;                 
         return $n;                 
         case 4:                 
         $n = (ord($c[0]) & 0x0f) << 18;                 
         $n += (ord($c[1]) & 0x3f) << 12;                 
         $n += (ord($c[2]) & 0x3f) << 6;                 
         $n += ord($c[3]) & 0x3f;                 
         return $n;                 
      }                 
   }

   function get_g_tk($skey){
      if(!$skey) return false;
      $hash = 5381;
      for($i=0;$i<strlen($skey);++$i){
         $hash += ($hash << 5) + ord($skey[$i]);
      }
      return $hash & 0x7fffffff;
   }
   echo jspassword('password','!DZW','\x00\x00\x00\x00\xa2\xfc\x7a\x80')."\n";
   echo getGTK("@gmj2sEfSM")."\n";
?

Diff文件目录比较工具

发布时间:December 7, 2013 // 分类:常用软件 // No Comments

常用参数:

-b 忽略空格数目的不同
-B 忽略空白行
-q 只列出两个文件有无差异,并不比较
-a 强制比较二进制文件
-c 显示不同之处的前后部分内容
-r 比较目录时,比较其子目录
-y 在两侧显示两个文件
--suppress-common-line 只显示两个文件不同的行,否则不显示
--left-column 仅当两个文件不同时才显示右侧行,否则只显示左侧行

示例:

diff -r -y --left-column dir1 dir2

URLEncode和Base64编码解码工具

发布时间:December 7, 2013 // 分类:PHP // No Comments

<?php 
   header("Content-Type: text/html; charset=utf-8"); 
   $code=$_POST['code']; 
   foreach ($_POST as $key=>$value) {
      if ($key == "URL") {
         if ($value=='Decode') { 
            $code=urldecode($code); 
         } 
         else $code=urlencode($code); 
      }
      if ($key == "Base64") {
         if ($value=='Decode') { 
            $code=base64_decode($code); 
         } 
         else $code=base64_encode($code); 
      }
   }
?> 
<html> 
   <body style="text-align: left;"> 
      <form action="" method='post'> 
         <textarea name='code' style="width:90%;height:45%;"><?php echo $_POST['code'];?></textarea> 
         <table>
            <tbody>
               <tr><td align="center">
                     <input type="submit" name="URL" value="Encode">
                     </td><td align="center">
                     URL
                     </td><td align="center">
                     <input type="submit" name="URL" value="Decode">
               </td></tr>
               <tr><td align="center">
                     <input type="submit" name="Base64" value="Encode">
                     </td><td align="center">
                     Base64
                     </td><td align="center">
                     <input type="submit" name="Base64" value="Decode">
               </td></tr>
            </tbody>
         </table>
      </form> 
      <textarea name='code' style="width:90%;height:45%;"><?php echo ($code);?></textarea>
   </body> 
</html>
分类
最新文章
最近回复
  • 海运: 恩山有很多。
  • swsend: 大佬可以分享一下固件吗,谢谢。
  • Jimmy: 方法一 nghtp3步骤需要改成如下才能编译成功: git clone https://git...
  • 海运: 地址格式和udpxy一样,udpxy和msd_lite能用这个就能用。
  • 1: 怎么用 编译后的程序在家里路由器内任意一台设备上运行就可以吗?比如笔记本电脑 m参数是笔记本的...
  • 孤狼: ups_status_set: seems that UPS [BK650M2-CH] is ...
  • 孤狼: 擦。。。。apcupsd会失联 nut在冲到到100的时候会ONBATT进入关机状态,我想想办...
  • 海运: 网络,找到相应的url编辑重发请求,firefox有此功能,其它未知。
  • knetxp: 用浏览器F12网络拦截或监听后编辑重发请求,修改url中的set为set_super,将POS...
  • Albert: 啊啊啊啊啊啊啊啊啊 我太激动了,终于好了英文区搜索了半天,翻遍了 pve 论坛没找到好方法,博...