Archive for 三月, 2010

bingou脑筋急转弯 @brain用法

星期三, 三月 31st, 2010

愚笨的bingou已经可以玩脑筋急转弯了
同学习模式一样
bingou可以判断第一个是否是@
如果是@进入特殊模式
脑筋急转弯是@brain
(全文…)

bingou问题学习@learn用法

星期三, 三月 31st, 2010

愚笨的bingou已经可以学说话了
首先
bingou可以判断第一个是否是@
如果是@进入特殊模式
@后面跟一个命令
比如学习那就是@learn
(全文…)

php 全角转半角

星期二, 三月 30th, 2010

找了几个函数
目前用的是第一个,虽然。。。不是很帅。。但是还是比较准的

/**  
 *  将一个字串中含有全角的数字字符、字母、空格或'%+-()'字符转换为相应半角字符  
 *  
 * @access  public  
 * @param   string       $str         待转换字串  
 *  
 * @return  string       $str         处理后字串  
 */  
function make_semiangle($str)   
{   
    $arr = array('0' => '0', '1' => '1', '2' => '2', '3' => '3', '4' => '4',   
                 '5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9',   
                 'A' => 'A', 'B' => 'B', 'C' => 'C', 'D' => 'D', 'E' => 'E',   
                 'F' => 'F', 'G' => 'G', 'H' => 'H', 'I' => 'I', 'J' => 'J',   
                 'K' => 'K', 'L' => 'L', 'M' => 'M', 'N' => 'N', 'O' => 'O',   
                 'P' => 'P', 'Q' => 'Q', 'R' => 'R', 'S' => 'S', 'T' => 'T',   
                 'U' => 'U', 'V' => 'V', 'W' => 'W', 'X' => 'X', 'Y' => 'Y',   
                 'Z' => 'Z', 'a' => 'a', 'b' => 'b', 'c' => 'c', 'd' => 'd',   
                 'e' => 'e', 'f' => 'f', 'g' => 'g', 'h' => 'h', 'i' => 'i',   
                 'j' => 'j', 'k' => 'k', 'l' => 'l', 'm' => 'm', 'n' => 'n',   
                 'o' => 'o', 'p' => 'p', 'q' => 'q', 'r' => 'r', 's' => 's',   
                 't' => 't', 'u' => 'u', 'v' => 'v', 'w' => 'w', 'x' => 'x',   
                 'y' => 'y', 'z' => 'z',   
                 '(' => '(', ')' => ')', '〔' => '[', '〕' => ']', '【' => '[',   
                 '】' => ']', '〖' => '[', '〗' => ']', '“' => '[', '”' => ']',   
                 '‘' => '[', '’' => ']', '{' => '{', '}' => '}', '《' => '<',   
                 '》' => '>',   
                 '%' => '%', '+' => '+', '—' => '-', '-' => '-', '~' => '-',   
                 ':' => ':', '。' => '.', '、' => ',', ',' => '.', '、' => '.',   
                 ';' => ',', '?' => '?', '!' => '!', '…' => '-', '‖' => '|',   
                 '”' => '"', '’' => '`', '‘' => '`', '|' => '|', '〃' => '"',   
                 ' ' => ' ');   
 
    return strtr($str, $arr);   
}

另外还有一个
看起来很帅的代码
不过貌似有问题
虽然全角是转半角了
但是有部分中文字也出错了貌似。

function &StrToDBC($str,$Encode='GBK'){
 if($Encode!='UTF8')$str=mb_convert_encoding($str,'UTF-8',$Encode);
 $ret='';
 for($i=0;$s1=$str[$i],$i<strlen($str);$i++){
  if(($c=ord($s1))&0x80){
   $s2=$str[++$i];
   $s3=$str[++$i];
   $c=(($c&0xF)<<12)|((ord($s2)&0x3F)<<6)|(ord($s3)&0x3F);
   if($c==12288){
    $ret.=' ';
   }elseif($c>65280&&$c<65375){
    $c-=65248;
    $ret.=chr($c);
   }else{
    $ret.=$s1.$s2.$s3;
   }
  }else{
   $ret.=$str[$i];
  }
 }

python http post数据表单

星期二, 三月 30th, 2010

学习PYTHON
(全文…)

动态磁盘不可读取/我手贱转了动态磁盘

星期三, 三月 24th, 2010

分区表损坏引起的,只要用软件重建分区表就可以了

http://www.cgsecurity.org/wiki/TestDisk_Download

PHP时间变成几秒前,几分前,几小时前,几天前SNS模式

星期五, 三月 19th, 2010

最近模仿UCHOME的DOING
我寸在MYSQL的时间都是unix时间。
(全文…)

jQuery的Ajax使用笔记 转

星期三, 三月 17th, 2010

jquery
1、代码简练、语义易懂、学习快速、文档丰富。
2、jQuery是一个轻量级的脚本,其代码非常小巧,最新版的java script包只有20K左右。
3、jQuery支持CSS1-CSS3,以及基本的xPath。
4、jQuery是跨浏览器的,它支持的浏览器包括IE 6.0+, FF 1.5+, Safari 2.0+, Opera 9.0+。
5、可以很容易的为jQuery扩展其他功能。
6、能将JS代码和HTML代码完全分离,便于代码和维护和修改。
7、插件丰富,除了jQuery本身带有的一些特效外,可以通过插件实现更多功能,如表单验证、tab导航、拖放效果、表格排序、
DataGrid,树形菜单、图像特效以及ajax上传等。
jQuery的设计会改变你写java script代码的方式,降低你学习使用JS操作网页的复杂度,提高网页JS开发效率,无论对于js初学者还
是资深专家,jQuery都将是您的首选。
jQuery适合于设计师、开发者以及那些还好者,同样适合用于商业开发,可以说jQuery适合任何java script应用的地方,可用于不同
的Web应用程序中。
(全文…)

一个jquery-ajax post例子ajax 登陆

星期三, 三月 17th, 2010

这个例子网上应该满多的
学习笔记 转载
index.html文件

<html> 
<head> 
<title>jQuery Ajax 实例演示</title> 
</head> 
<script src="./js/jquery.js" type="text/java script"></script>  
<script type="text/java script">
$(document).ready(function(){//这个就是jQueryready  ,它就像C语言的main 所有操作包含在它里面
    $("#button_login").mousedown(function(){ 
   login(); //点击ID为"button_login"的按钮后触发函数 login();
    });
});
function login(){ //函数 login();
 var username = $("#username").val();//取框中的用户名
 var password = $("#password").val();//取框中的密码
 $.ajax({ //一个Ajax过程  
   type: "post",  //以post方式与后台沟通
   url : "login.php", //与此php页面沟通
   dataType:'json',//从php返回的值以 JSON方式 解释
   data:  'username='+username+'&password='+password, //发给php的数据有两项,分别是上面传来的u和p   
   success: function(json){//如果调用php成功
 
                        //alert(json.username+'\n'+json.password); //把php中的返回值(json.username)给 alert出来
 
   $('#result').html("姓名:" + json.username + "<br/>密码:" + json.password); //把php中的返回值显示在预定义的result
定位符位置 
 
 
                          }   
           });
 
 
 
  //$.post()方式:  
  $('#test_post').mousedown(function (){  
    $.post(  
      'login.php',  
      {  
        username:$('#username').val(),  
        password:$('#password').val() 
      },  
      function (data) //回传函数  
      {  
        var myjson='';  
        eval('myjson=' + data + ';');  
        $('#result').html("姓名1:" + myjson.username + "<br/>密码1:" + myjson.password);  
      }  
    );  
   }); 
 
 
 
  //$.get()方式:  
  $('#test_get').mousedown(function ()  
  {  
    $.get(  
      'login.php',  
      {  
        username:$('#username').val(),  
        password:$('#password').val() 
      },  
      function(data) //回传函数  
      {  
        var myjson='';  
        eval("myjson=" + data + ";");  
        $('#result').html("姓名2:" + myjson.username + "<br/>密码2:" + myjson.password);   
      }  
    );  
  });  
 
 
 
 
 }
</script>
<body> 
 <div id="result" style="background:orange;border:1px solid red;width:300px;height:200px;"></div> 
 
  <form id="formtest" action="" method="post"> 
 
    <p><span>输入姓名:</span><input type="text" name="username" id="username" /></p> 
    <p><span>输入密码:</span><input type="text" name="password" id="password" /></p> 
  </form> 
  <button id="button_login">ajax提交</button> 
 
  <button id="test_post">post提交</button> 
 
  <button id="test_get">get提交</button> 
 
 
 
</body> 
</html>

login.php文件

<?php
echo json_encode(array ('username'=>$_REQUEST['username'],'password'=>$_REQUEST['password']));
?>

php jquery ajax中文乱码

星期二, 三月 16th, 2010

PHP发送中文、Ajax接收
只需在php顶部加入一句:

header('Content-type: text/html;charset=GB2312');

xmlHttp会正确解析其中的中文。

Ajax发送中文、PHP接收
这个比较复杂:
Ajax中先用encodeURIComponent对要提交的中文进行编码
PHP中:

$view=iconv( 'UTF-8', 'gb2312//IGNORE' , $_POST['view']);

PHP使用reCAPTCHA作为验证码来保护您的网站

星期一, 三月 15th, 2010

CAPTCHA,其全称是“全自动区分计算机和人类的图灵测试”(completely automated public Turing test to tell computers and humans apart)。
现在通过使用 Google免费的reCAPTCHA服务,您可以轻松地在您自己的网站上利用这项技术。
首先
我们需要申请一个 KEY
类似于GOOGLE MAP的API KEY一样
在reCAPTCHA网站注册一个API key(免费)。并记录下你的private key和 public key。
https://admin.recaptcha.net/accounts/signup/
然后去GOOGLE CODE 下载类库
http://code.google.com/p/recaptcha/downloads/list?q=label:phplib-Latest

调用类

require_once('recaptchalib.php');
$publickey = "..."; // you got this from the signup page
echo recaptcha_get_html($publickey);

验证部分

require_once('recaptchalib.php');
$privatekey = "...";
$resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);
 
if (!$resp->is_valid) {
  die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
       "(reCAPTCHA said: " . $resp->error . ")");
}

官方还提供了一个 EXAMPLE

<html>
  <body>
    <form action="" method="post">
<?php
 
require_once('recaptchalib.php');
$publickey = "...";
$privatekey = "...";
 
# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = null;
 
# are we submitting the page?
if ($_POST["submit"]) {
  $resp = recaptcha_check_answer ($privatekey,
                                  $_SERVER["REMOTE_ADDR"],
                                  $_POST["recaptcha_challenge_field"],
                                  $_POST["recaptcha_response_field"]);
 
  if ($resp->is_valid) {
    echo "You got it!";
    # in a real application, you should send an email, create an account, etc
  } else {
    # set the error code so that we can display it. You could also use
    # die ("reCAPTCHA failed"), but using the error message is
    # more user friendly
    $error = $resp->error;
  }
}
echo recaptcha_get_html($publickey, $error);
?>
    <br/>
    <input type="submit" name="submit" value="submit" />
    </form>
  </body>
</html>