shell sort (希尔排序)

http://my.opera.com/419/homes/labs/files/shellsort.html 看后修改的一个用于php数组的排序
<?php
function shellsort($array,$n)
{
 for ($gap =(int) $n/2;$gap=(int)$gap,$gap > 0; $gap /= 2){
   for ($i = $gap; $i < $n; $i++){
     for ($j = $i-$gap; $j>=0 && $array[$j]>$array[($j+$gap)]; $j -= $gap) {
       $temp = $array[$j];
       $array[$j] = $array[($j+$gap)];
       $array[($j+$gap)] = $temp;
     }
   }
 }
     return $array;
}
$array=array(85,40, 79, 80, 92, 20, 34, 77);

$new_array=shellsort($array,count($array));
print_r($new_array);
?>

email地址php检测

利用正则表达式     使用方法如下,具体函数请看详情
if (check_email_address($email)) {
  echo $email . ‘ is a valid email address.’;
} else {
  echo $email . ‘ is not a valid email address.’;
}   
function check_email_address($email) {
  // First, we check that there’s one @ symbol, and that the lengths are right
  if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
    // Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
    return false;
  }
  // Split it into sections to make life easier
  $email_array = explode("@", $email);
  $local_array = explode(".", $email_array[0]);
  for ($i = 0; $i < sizeof($local_array); $i++) {
     if (!ereg("^(([A-Za-z0-9!#$%&’*+/=?^_`{|}~-][A-Za-z0-9!#$%&’*+/=?^_`{|}~.-]{0,63})|("[^(\|")]{0,62}"))$", $local_array[$i])) {
      return false;
    }
  }  
  if (!ereg("^[?[0-9.]+]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name
    $domain_array = explode(".", $email_array[1]);
    if (sizeof($domain_array) < 2) {
        return false; // Not enough parts to domain
    }
    for ($i = 0; $i < sizeof($domain_array); $i++) {
      if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {
        return false;
      }
    }
  }
  return true;
}

获取MySQL数据表的大小

                $sql="SHOW TABLE STATUS FROM `".$database."` LIKE ‘".$table."’";
                $result=mysql_query($sql);
                $array=mysql_fetch_array($result,MYSQL_ASSOC);
echo $array[‘Data_length’];

表单提交时自动复制内容到剪贴板

今天在网络上发现了这个小东西,这功能虽然非常小,但有时候却非常有用。

估计你也有过这种经历:长篇大论后提交,发现"该页无法显示",或者"登录超时"…

然后,你不得不捶桌子?哈哈

如何在页面里加入,就看你自己的了,会html的都会的

代码如下:     IE ONLY

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>交时自动复制到剪贴板</title>
</head>

<script language="JavaScript">
// 功能:提交时自动复制到剪贴板

function copyText(obj) {
    ie = (document.all)? true:false;
    if (ie) {
        var rng = document.body.createTextRange();
        rng.moveToElementText(obj);
        rng.scrollIntoView();
        rng.select();
        rng.execCommand("Copy");
        rng.collapse(false);
    }
}

function autocopy() {
    if (this.document.formname.isautocopy.checked) { 
        copyText(this.document.formname.icontent);
    }
}
</script>

<body>
<form action=""  method="post" name="formname" onsubmit="autocopy();">
<textarea name="icontent" rows="4" cols="50"></textarea><br>
<input name="isautocopy" checked="checked" value="1" type="checkbox" />
提交时复制内容到剪贴板<br/><input type="submit" value="提交" /> </form>

</body>
</html>

用php模拟post来提交数据

利用php的socket编程来直接给接口发送数据来模拟post的操作。<?PHP /************************************************************************
Name: POST 测试程序 Vesion: 1.0 Date: 2004-08-05 *************************************************************************
/ $flag = 0;
 //要post的数据
$argv = array(
    ‘var1’=>’abc’,
    ‘var2’=>’你好吗’);
//构造要post的字符串
foreach ($argv as $key=>$value) {
    if ($flag!=0) {
        $params .= "&";
        $flag = 1;
    }
    $params.= $key."="; $params.= urlencode($value);
    $flag = 1;
    }
    $length = strlen($params);
     //创建socket连接
    $fp = fsockopen("127.0.0.1",80,$errno,$errstr,10) or exit($errstr."—>".$errno);
    //构造post请求的头
    $header = "POST /mobile/try.php HTTP/1.1
";
    $header .= "Host:127.0.0.1
";
    $header .= "Referer:/mobile/sendpost.php
";
    $header .= "Content-Type: application/x-www-form-urlencoded
";
    $header .= "Content-Length: ".$length."
";
    $header .= "Connection: Close

";
    //添加post的字符串
    $header .= $params."
";
    //发送post的数据
    fputs($fp,$header);
    $inheader = 1;
    while (!feof($fp)) {
        $line = fgets($fp,1024); //去除请求包的头只显示页面的返回数据
        if ($inheader && ($line == "
" || $line == "
")) {
             $inheader = 0;
        }
        if ($inheader == 0) {
            echo $line;
        }
    }
fclose($fp);
?>

还可以使用php类HttpClient

Snoopy http://sourceforge.net/projects/snoopy/
or httpClient http://scripts.incutio.com/httpclient/

自动选择最快镜像

<img alt="站点一" onerror="location=’站点一的地址’" src="站点一上一个不存在的图片" width="1" height="1"/>
<img alt="站点二" onerror="location=’站点二的地址’" src="站点二上一个不存在的图片" widht="1" height="1"/>
只是一个思路,主要测试目标服务的响应速度

提交按钮的效果

有的时候,要让别人看服务条款,所以不让他立即注册,显示倒计时<script>
function re_js(gree){
if(gree){
form1.Submit.disabled=false
}else{
form1.Submit.disabled=true;
}
}

var i=20;
function re_jump(){
    document.form1.Submit.value="请仔细阅读协议,"+i+"秒";
    if(i>0){
        setTimeout("re_jump()",1000);
    }else{
        document.form1.Submit.value="进行下一步";
    }
    i=i-1;
}
setTimeout("re_jump()",1);
</script>

<input name="gree" type="checkbox" id="gree" value="1" onClick="re_js(this.checked)">
已经阅读协议,并同意协议中的各项条款</td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td height="0" colspan="2" bgcolor="#CCCCCC"> <div align="center"></div></td>
</tr>

<tr>
<td height="-1" colspan="2">&nbsp;</td>
</tr>
<tr>
<td  >用户名:</td>
<td  ><input name="username" type="text" id="username" size="17" maxlength="17" class="text">
<input type="submit" name="Submit" value="进行下一步" class="subbt3" disabled>