一次在上数据结构的课程时,突然想测试下自己的英文打字的速度。
可郁闷的是网上找了半天也没找出个结果,很多的是做成软件的形式,我想如果有个网页式的打字测试那很方便咯!也省的去下载客户端软件了,呵呵。。。
于是自己便想试着用自己学了一点时间的PHP,写下在线打字程序。
在次把代码贴出,这个只是一个初级的打字页面。本人设置了初、中、高三个等级!(*^__^*) 嘻嘻……原理差不多!
这个是初级的程序页面!
<?php
//error_reporting(E_ALL);
error_reporting(0); //屏蔽warning
?>
<html>
<head>
<title>在线测试英文打字速度</title>
<META NAME="save" CONTENT="history">
<STYLE>
.sHistory {behavior:url(#default#savehistory);}
</STYLE>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var ms = 0;
var state = 0;
function startstop()
{
if (state == 0)
{
state = 1;
then = new Date();
then.setTime(then.getTime() - ms);
}
else
{
state = 0;
now = new Date();
ms = now.getTime() - then.getTime();
document.stpw.time.value = ms;
}
}
function swreset()
{
state = 0;
ms = 0;
document.stpw.time.value = ms;
}
function display()
{
setTimeout("display();", 50);
if (state == 1)
{
now = new Date();
ms = now.getTime() - then.getTime();
document.stpw.time.value = ms;
}
}
// End -->
</SCRIPT>
</head>
<body topmargin="0" onLoad="display()" onselectstart="return false" onpaste="alert('想偷懒么?');" oncopy="return false;" oncut="return false;" oncontextmenu="window.event.returnValue=false">
<form action="" method="post" name="stpw" valign="top">
<table align="center" cellspacing="10" cellpadding="0" border="0">
<tr width="200" align="left">
<td style="color:red"> 请选择想要挑战的级别((*^__^*) 嘻嘻……):</td>
<td><input name="magic" value="basic" type="radio" onclick="javascript:location.href='basic.php';" checked>初级</td>
<td> <input name="magic" value="middle" type="radio" onclick="javascript:location.href='middle.php';">中级</td>
<td><input name="magic" value="high" type="radio" onclick="javascript:location.href='high.php';">高级</td>
</tr>
<tr width="200">
<td colspan="4" width="800">范文:<br>
Good morning ! It is really my honor to have this opportunity for a interview, I hope i can make a good performance today. I'm confident that I can succeed. Now i will introduce myself briefly I am 26 years old,born in shandong province . <br>
I was graduated from qingdao university. my major is electronic.and i got my bachelor degree after my graduation in the year of 2003.<br>
</td>
</tr>
<tr>
<td colspan="4">开始测试喽<font color="red">(在下面的输入框开始打字吧):</font><br>
<b>计时开始:</b><INPUT TYPE="text" Name="time" class=sHistory>
<INPUT TYPE="BUTTON" Name="ssbutton" VALUE="开始/停止" onClick="startstop()">
<INPUT TYPE="BUTTON" NAME="reset" VALUE="重置" onClick="swreset()">
</td>
</tr>
<tr>
<td colspan="3">
<textarea name="in" cols="70" rows="20" wrap="on" onfocus="
" onBlur=""></textarea></td>
<td ><input name="ssbutton" type="submit" value="点击往下看结果吧"><input type="hidden" name="wtime" value=""></td>
</tr>
</table>
</form>
<div style="margin-left:90">
<?php
if($_POST['ssbutton']=="点击往下看结果吧")
{
$total=$_POST['in'];
$time=$_POST['time'];
$arr = explode(" ",$total); //explode 的作用是把字符串分割为数组
foreach ($arr as $value)
{ $result.=$value; }
$num=strlen($result);
$ltime=(int)($time/1000);
echo "测试的结果为:";
echo "<br>总输入为:<font color='red'>".$num."个</font>";
echo " 所使用的时间为:<font color='red'>".$ltime."秒</font>";
if($ltime==0)
{
echo " 您最终的打字速度为:<font color='red'>0个/秒</font>";
}
else
{
echo " 您最终的打字速度为:<font color='red'>".$num/$ltime."个/秒</font>";
}
}
?>
</font>
</div>
</body>
已经在本地测试通过了,不过觉得代码还是有些生硬,不是很美!
我知道还有很多的地方还值得去推敲下!如果大家有什么好的建议,可以提出来啊!大家可以讨论下!
搞了一天的东东了,终于有成果了哈!(*^__^*) 嘻嘻……开心咯!
可郁闷的是网上找了半天也没找出个结果,很多的是做成软件的形式,我想如果有个网页式的打字测试那很方便咯!也省的去下载客户端软件了,呵呵。。。
于是自己便想试着用自己学了一点时间的PHP,写下在线打字程序。
在次把代码贴出,这个只是一个初级的打字页面。本人设置了初、中、高三个等级!(*^__^*) 嘻嘻……原理差不多!
这个是初级的程序页面!
<?php
//error_reporting(E_ALL);
error_reporting(0); //屏蔽warning
?>
<html>
<head>
<title>在线测试英文打字速度</title>
<META NAME="save" CONTENT="history">
<STYLE>
.sHistory {behavior:url(#default#savehistory);}
</STYLE>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var ms = 0;
var state = 0;
function startstop()
{
if (state == 0)
{
state = 1;
then = new Date();
then.setTime(then.getTime() - ms);
}
else
{
state = 0;
now = new Date();
ms = now.getTime() - then.getTime();
document.stpw.time.value = ms;
}
}
function swreset()
{
state = 0;
ms = 0;
document.stpw.time.value = ms;
}
function display()
{
setTimeout("display();", 50);
if (state == 1)
{
now = new Date();
ms = now.getTime() - then.getTime();
document.stpw.time.value = ms;
}
}
// End -->
</SCRIPT>
</head>
<body topmargin="0" onLoad="display()" onselectstart="return false" onpaste="alert('想偷懒么?');" oncopy="return false;" oncut="return false;" oncontextmenu="window.event.returnValue=false">
<form action="" method="post" name="stpw" valign="top">
<table align="center" cellspacing="10" cellpadding="0" border="0">
<tr width="200" align="left">
<td style="color:red"> 请选择想要挑战的级别((*^__^*) 嘻嘻……):</td>
<td><input name="magic" value="basic" type="radio" onclick="javascript:location.href='basic.php';" checked>初级</td>
<td> <input name="magic" value="middle" type="radio" onclick="javascript:location.href='middle.php';">中级</td>
<td><input name="magic" value="high" type="radio" onclick="javascript:location.href='high.php';">高级</td>
</tr>
<tr width="200">
<td colspan="4" width="800">范文:<br>
Good morning ! It is really my honor to have this opportunity for a interview, I hope i can make a good performance today. I'm confident that I can succeed. Now i will introduce myself briefly I am 26 years old,born in shandong province . <br>
I was graduated from qingdao university. my major is electronic.and i got my bachelor degree after my graduation in the year of 2003.<br>
</td>
</tr>
<tr>
<td colspan="4">开始测试喽<font color="red">(在下面的输入框开始打字吧):</font><br>
<b>计时开始:</b><INPUT TYPE="text" Name="time" class=sHistory>
<INPUT TYPE="BUTTON" Name="ssbutton" VALUE="开始/停止" onClick="startstop()">
<INPUT TYPE="BUTTON" NAME="reset" VALUE="重置" onClick="swreset()">
</td>
</tr>
<tr>
<td colspan="3">
<textarea name="in" cols="70" rows="20" wrap="on" onfocus="
" onBlur=""></textarea></td>
<td ><input name="ssbutton" type="submit" value="点击往下看结果吧"><input type="hidden" name="wtime" value=""></td>
</tr>
</table>
</form>
<div style="margin-left:90">
<?php
if($_POST['ssbutton']=="点击往下看结果吧")
{
$total=$_POST['in'];
$time=$_POST['time'];
$arr = explode(" ",$total); //explode 的作用是把字符串分割为数组
foreach ($arr as $value)
{ $result.=$value; }
$num=strlen($result);
$ltime=(int)($time/1000);
echo "测试的结果为:";
echo "<br>总输入为:<font color='red'>".$num."个</font>";
echo " 所使用的时间为:<font color='red'>".$ltime."秒</font>";
if($ltime==0)
{
echo " 您最终的打字速度为:<font color='red'>0个/秒</font>";
}
else
{
echo " 您最终的打字速度为:<font color='red'>".$num/$ltime."个/秒</font>";
}
}
?>
</font>
</div>
</body>
已经在本地测试通过了,不过觉得代码还是有些生硬,不是很美!
我知道还有很多的地方还值得去推敲下!如果大家有什么好的建议,可以提出来啊!大家可以讨论下!
搞了一天的东东了,终于有成果了哈!(*^__^*) 嘻嘻……开心咯!