计算缘分

来源:互联网 发布:mac air display 编辑:程序博客网 时间:2024/04/28 10:22
  1. <?php      
  2. header('content-type:text/html;charset=utf8 ');  
  3.   
  4. $uname1=md5($_POST['uname1']);  
  5. $uname2=md5($_POST['uname2']);  
  6. //echo $uname1.'/'.$uname2;die;  
  7. $length=strlen($uname1);//长度  
  8.   
  9. $score=0;//重复数  
  10. $repeat=1;//重复长度  
  11.   
  12. for ($i=0; $i < $length; $i++) {   
  13.     if($uname1[$i]==$uname2[$i]){  
  14.         $score+=10;  
  15.   
  16.         if($i>0){  
  17.             if($uname1[$i-1]==$uname2[$i-1]){  
  18.                 $repeat++;//计算重复值得长度  
  19.             }else{  
  20.                 if($repeat>1){  
  21.                     $score+=$repeat*10;//不重复后直接计算结果  
  22.                     $repeat=1;  
  23.                 }  
  24.             }  
  25.         }  
  26.     }  
  27. }  
  28. //最后得到结果  
  29. if($repeat>1){  
  30.     $score+=$repeat*10;  
  31. }  
  32. //输出  
  33. echo "<script>alert('你们的缘分指数是:".$score."分');location.href='form.html'</script>";  
  34.   
  35.  ?> 
0 0
原创粉丝点击