PHP删除数组重复元素函数

function delsame(&$array)
{
$i = 0;
while(isset($array[$i]))
{
$j = $i + 1;
while(isset($array[$j]))
{
if($array[$i] == $array[$j]) //如果发现后面有重复的元素
{
delmember($array, $j); //把它删除
$j--; //重新检查补上来的元素是否是重复的
}
$j ++;
}
$i ++;
}
}

阅读全文

php ajax仿dedecms 验证新闻是否存在

<script language="网页特效">
function startrequestusingpost() {
         if(checktitle()==false)
         {
               return;
         }
           var title = document.getelementbyid("title").value;
           createxmlhttprequest();
           xmlhttp.open("post","checkntype",true);
           xmlhttp.onreadystatechange = processresponse;
           xmlhttp.setrequestheader("content-type","application/x-www-form-urlencoded");
           xmlhttp.send("title=" + title);
      }
     
      function processresponse() {
           if(xmlhttp.readystate == 4) {
                if(xmlhttp.status == 200) {
                    var result = xmlhttp.responsetext;
              if(result==1){
                document.getelementbyid("message").style.display="inline";
                document.getelementbyid("btnadd").disabled="disabled";
                }else
                {
                  document.getelementbyid("message").style.display="none";
                 document.getelementbyid("btnadd").disabled="";
                 }
                }
           }
      }
      function checktitle()
      {
       var title=document.getelementbyid("title").value;
          if(title=="")
          {
           document.getelementbyid("lbltitle").style.display="inline";
            return false;
          }else
          {
          document.getelementbyid("lbltitle").style.display="none";
           return true;
       }
      }

阅读全文

PHP删除数组元素与删除重复数组函数

$a=array("red", "green", "blue", "yellow");   
count($a); //得到4   
unset($a[1]); //删除第二个元素   
count($a); //得到3   
echo $a[2]; //数组中仅有三个元素,本想得到最后一个元素,但却得到blue,   
echo $a[1]; //无值 

阅读全文

php删除目录及目录下所有文件子目录

<?php教程
set_time_limit(0);
$filenum=0;
function deldir($dir){
 global $filenum;
 $dh=opendir($dir);
 while ($file=readdir($dh)){
  if($file!="."&&$file!=".."){
   $fullpath=$dir."/".$file;
    if(!is_dir($fullpath)){
     unlink($fullpath);
    if(($filenum %100)==0){
     echo "*";
    }
    $filenum=$filenum+1;
   }else{
    deldir($fullpath);
   }
  }
 }
 closedir($dh);
}
deldir("/www.phprm.com/");
echo "delete cache file success. total:".$filenum;
?>

阅读全文

php生成随机密码函数(四款)

方法一

function generate_password( $length = 8 ) {
    // 密码字符集,可任意添加你需要的字符
    $chars = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_ []{}<>~`+=,.;:/?|';

阅读全文