php基础知识的灵活使用
来源:互联网 发布:时尚杂志推荐 知乎 编辑:程序博客网 时间:2024/06/06 23:28
问题描述:在后台比较将两个名称md5后的字符串(str1和str2),如果str1和str2在相同位置的字符相同则记10分,如果相连的字符有n个,则在原来基础上再加上 n*10,最后得出的总分数为他们之间的缘分。
举例:
Str1 = abced;
Str2 = abf1d;
则得分为(10 + 10 + 2*10 + 10) = 50分
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Document</title>
</head>
<body>
<center>
<form action="index.php?r=yuanf/index" method="post">
<table>
<tr>
<td><input type="text" name="uname1"/></td>
<td>和</td>
<td><input type="text" name="uname2"/></td>
<td><input type="submit" value="计算得分"/></td>
</tr>
<tr>
<td colspan="4"><textarea rows="5" cols="60"></textarea></td>
</tr>
</table>
</form>
</center>
</body>
</html>
<?php
namespace frontend\controllers;
use Yii;
use common\models\LoginForm;
use yii\base\InvalidParamException;
use yii\web\BadRequestHttpException;
use yii\web\Controller;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
/**
* Yuan controller
*/
class YuanfController extends Controller
{
public $enableCsrfValidation = false;
public function actionYuanf(){
return $this->render('yuanf.html');
}
//测试缘分
public function actionIndex(){
$uname1=md5($_POST['uname1']);
$uname2=md5($_POST['uname2']);
//echo $uname1;die;
$length=strlen($uname1);//长度
$score=0;//重复数
$repeat=1;//重复长度
for ($i=0; $i < $length; $i++) {
if($uname1[$i]==$uname2[$i]){
$score+=10;
if($i>0){
if($uname1[$i-1]==$uname2[$i-1]){
$repeat++;//计算重复值得长度
}else{
if($repeat>1){
$score+=$repeat*10;//不重复后直接计算结果
$repeat=1;
}
}
}
}
}
//最后得到结果
if($repeat>1){
$score+=$repeat*10;
}
//输出
echo "<script>alert('你们的缘分指数是:".$score."分');location.href='index.php?r=yuanf/yuanf'</script>";
}
- php基础知识的灵活使用
- 灵活的php date
- Log4j 的灵活使用
- TRECT的灵活使用
- TRECT的灵活使用
- TRECT的灵活使用
- getchar()的灵活使用
- angularJs的灵活使用
- Visio的灵活使用
- 文件的上传灵活使用
- 双网卡的灵活使用
- thinkphp 缓存的灵活使用
- 灵活的使用try catch
- Session对象的灵活使用
- PHP的基础知识
- php的基础知识总结
- PHP的基础知识
- PHP的函数基础知识
- 创建目录/文件
- iOS开发 适配iOS10以及Xcode8
- php apache 配置
- 理解APCS-- ARM过程调用标准
- 常用的正则表达
- php基础知识的灵活使用
- skynet框架 源码分析 一
- C#将Bitmap转换成byte[],可以传给C++处理。
- 第7周项目4 队列数组
- java io系列22之 FileReader和FileWriter
- android设置TextView中文字不同的颜色
- 第7周项目4-队列数组
- 通知
- springmvc+ajax 实现jquer autocomplete 联想查询(动态添加、删除行)