实 验 环 境 | wamp Server+ phpDesigner/vs Code |
实 验 目 的 | 掌握if语句和switch语句的作用、语法、执行流程和使用; 掌握自定义函数的定义、传参、返回值、调用和使用; 掌握date和similar_text等系统函数; 能应用函数设计和实现系统。 |
任务1:设计和实现节日识别模块,该模块可判断当日是否为节日(元旦、清明、五一、六一、八一、国庆),并提示节日快乐。
任务2:设计和实现文章抄袭检测系统,雷同率高于30%则判定为“抄袭”,否则判定为“未抄袭”,并生成文章抄袭检测报告(界面自行设计)。
此实验是笔者在学校的PHP实验内容。
效果图:
首页:
检测报告页面:
代码展示:
首页 index.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>文章抄袭检测系统</title>
<link rel="stylesheet" href="index.css">
</head>
<body>
<div class="box">
<h2><strong>文章抄袭检测系统</strong></h2>
<form action="article.php" method="post">
<h3>检测的文章</h3>
<br><br><textarea name="article1" id="" cols="90" rows="10"></textarea>
<hr>
<h3>对比的文章</h3>
<br><br><textarea name="article2" id="" cols="90" rows="10"></textarea>
<br>
<input type="submit" value="开始检测" id="btn">
</form>
</div>
<div class="left_tu">
<img src="./top.jpg" alt="">
<img src="./xia.jpg" alt="">
</div>
<div class="message">
<?php
$date = date("Y年m月d日");
?>
<h4>亲爱的用户您好,<br><br>今天是:<?php
echo $date;
?>
<br><br>
<?php
$d = date("m月d日");
// echo $d;
switch ($d) {
case "01月01日":
echo "是元旦日,祝用户阖家快乐";
break;
case "04月04日":
echo "是清明节,祝用户阖家快乐";
break;
case "05月01日":
echo "是五一节,祝用户阖家快乐";
break;
case "06月01日":
echo "是六一节,祝用户阖家快乐";
break;
case "08月01日":
echo "是八一节,祝用户阖家快乐";
break;
case "10月01日":
echo "是国庆节,祝用户阖家快乐";
break;
}
?>
</h4>
</div>
</body>
</html>
首页CSS样式
index.css
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background-image: url(./beijing.jpg);
background-repeat: no-repeat;
background-size: cover;
}
.box {
width: 800px;
height: 800px;
border: 1px solid #e6e6e6;
/* margin: 100px auto; */
margin-left: 650px;
margin-top: 100px;
border-radius: 15px;
background-color: rgba(255, 255, 255, 0.5);
box-shadow: 0 5px 5px rgba(0, 0, 0, 0.3);
padding-top: 15px;
}
.box h2{
font-weight: 400;
text-align: center;
}
.box form {
margin: 50px;
}
.box h3 {
font-weight: 400;
font-size: 25px;
}
.box form textarea {
outline: rgb(90, 25, 1);
}
hr {
margin: 50px 0;
}
#btn {
width: 672px;
height: 50px;
font-size: 25px;
cursor: pointer;
margin-top: 15px;
}
.message {
width: 600px;
height: 400px;
border: 1px solid #dadada;
position: absolute;
top: 100px;
left: 50px;
transition: all 10s;
margin-top: -500px;
box-shadow: 0 5px 5px rgba(0, 0, 0, 0.3);
}
body:hover .message{
margin-top:0px ;
}
.message {
background: url(./th.jpg) no-repeat;
background-size: 100% 100%;
}
.message h4 {
font-weight: 400;
font-size: 40px;
color: orangered;
margin-top: 100px;
padding-left: 50px;
}
.left_tu{
width: 600px;
height: 800px;
/* border: 1px solid black; */
position: absolute;
left: 50px;
top: 100px;
margin: 0;
padding: 0;
}
.left_tu img{
background-repeat: no-repeat;
width: 600px;
height: 400px;
background-size: cover;
box-shadow: 0 5px 5px rgba(0, 0, 0, 0.3);
}
文章检测代码
article.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background-color: #f0f0f0;
}
.box {
background-image: url(main.jpg);
width: 760px;
height: 600px;
/* border: 1px solid #000; */
margin: 100px auto;
}
h1 {
color: #FFF;
font-weight: 400;
text-align: center;
padding-top: 50px;
}
li {
list-style: none;
}
.left {
width: 200px;
float: left;
margin-top: 15px;
margin-left: 115px;
background-color: antiquewhite;
}
.left ul li {
height: 50px;
line-height: 50px;
text-align: center;
border: 1px solid #000;
}
.right {
width: 350px;
float: left;
margin-top: 15px;
background-color: grep;
opacity: 0.5;
background-color: #445158;
}
.right ul li {
color: #FFF;
height: 50px;
line-height: 50px;
text-align: center;
border: 1px solid #000;
overflow: hidden;
}
nav{
width: 10rem;
height: 20rem;
position: absolute;
top: 0;
left: 16rem;
margin: 100px;
/* padding-left: 3rem; */
}
</style>
</head>
<body>
<?php
function getArticle1(){
// 获取第一篇文章
$article1 = $_REQUEST['article1'];
return $article1;
}
function getArticle2(){
//获取第二篇文章
$article2 = $_REQUEST['article2'];
return $article2;
}
//调用函数检测
function check($article1,$article2){
//查重内容去掉标点符号
$article1 = str_replace(array(',', '.', '!', '?', ';', ':',',','?','。','!','@'), '', $article1);
$article2 = str_replace(array(',', '.', '!', '?', ';', ':',',','?','。','!','@'), '', $article2);
//统一大小写字母
$article1 = strtolower($article1);
$article2 = strtolower($article2);
similar_text($article1,$article2,$percent);
//相同内容标红
$diff = str_replace($article2, '<span style="color: red;">' . $article1 . '</span>', $article2);
return array(
'percent' => $percent,
'diff' => $diff,
);
// return $percent;
}
//结论
function consulation($percent){
//限定结果
$thre=30.0;
$conculsion=false;//正常
if($percent>$thre)
$conculsion=true;
return $conculsion;
}
//显示界面函数
// function display(){
// echo "<table>";
// echo "<tr>";
// echo "<td>第一篇文章的内容</td>";
// echo "</tr>";
// echo "</table>";
// }
//获取来两篇文章
$article1=getArticle1();
$article2=getArticle2();
//调用检测方法
$result = check($article1, $article2);
//调用返回结果
// $conculsion=consulation($percent);
?>
<div class="box">
<h1>检测结果报告</h1>
<div class="left">
<ul>
<li>第一篇文章</li>
<li>第二篇文章</li>
<li>时间</li>
<li>结果</li>
<li>雷同率</li>
<li>重复内容</li>
</ul>
</div>
<div class="right">
<ul>
<li>
<?php
echo $article1;
?>
</li>
<li>
<?php
echo $article2;
?>
</li>
<li>
<?php
echo date("Y年m月d日");
?>
</li>
<li>
<?php
$conculsion=consulation($result['percent']);
if($conculsion==true){
echo "抄袭";
} else {
echo "正常";
}
?>
</li>
<li>
<?php
// $percent=check($article1,$article2);
// echo round($percent,2)."%";
echo round($result['percent'],2)."%";
?>
</li>
<li>
<?php
if($result['percent']==0){
echo"无";
}else
echo $result['diff'];
?>
</li>
</ul>
</div>
</div>
</body>
</html>
注意:此项目是笔者在学校的实验项目,笔者在这里就不提供页面中的图片了,大家可以在网上随便找图代替,因为笔者的能力有限,会出现很多的问题,如果您在阅读或者运行代码的时候出现了一些问题,还请您在评论区留言,笔者会在第一时间解决。