Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
Yes you can get , I guess next question would be how to make it work ?
ithelp
Nearly a Posting Maven
2,230 posts since May 2006
Reputation Points: 769
Solved Threads: 128
Although it is possible, you will find that the typing speed php calculates will be slower than the real typing speed due to page loading and submitting time. For this reason you should deduct about 1 second from the overall time if the page has no graphics.
As for how to make it work, I would suggest placing in a hidden field the time the page was loaded then when the page is submitted, that time that was recorded can be compared to the current time to work out how long it took. Then do number of characters they typed devided by 3. Then do time it took devided by the previous result (the devide by 3 result). Then do 1 devided by the result. Really simple stuff but as I mentioned, an online typing test will not be 100% accurate due to page loading time and the time for submitting the results. Also note that when timing typing speed, one word normally = 3 characters.
cwarn23
Occupation: Genius
3,033 posts since Sep 2007
Reputation Points: 413
Solved Threads: 259
I just need a basic php code so that I can edit it. Thanks.
If it's simple, why can't you write it? And if you can't write it, what makes you think you can edit it?
Ezzaral
Posting Genius
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
If it's simple, why can't you write it? And if you can't write it, what makes you think you can edit it?
Well if you would like an example the following is a script which will do the job.
<?
error_reporting(E_ALL ^ E_NOTICE);
$time=date('G-i-s-u'); //nj
echo 'You may test yourself by typing in the below field and clicking submit. Timer immediately after the page loads.';
if (isset($_POST['typetext'])) {
$time_end=explode('-',$time);
$time_start=explode('-',$_POST['timestart']);
$time_start[0]=bcmul($time_start[0],'3600000000');
$time_start[1]=bcmul($time_start[1],'60000000');
$time_start[2]=$time_start[2]*1000000;
$start_time=bcadd(bcadd($time_start[0],$time_start[1]),bcadd($time_start[2],$time_start[3]));
$time_end[0]=bcmul($time_end[0],'3600000000');
$time_end[1]=bcmul($time_end[1],'60000000');
$time_end[2]=$time_end[2]*1000000;
$end_time=bcadd(bcadd($time_end[0],$time_end[1]),bcadd($time_end[2],$time_end[3]));
$totaltime=bcsub($end_time,$start_time);
//above calculates the total time with great accuracy
$totaltime=bcdiv($totaltime,1000000);
if ($_SERVER['SERVER_NAME']!=='localhost') { $totaltime-=1000000; }
if (strlen($_POST['typetext'])) {
$chars=strlen($_POST['typetext']);
$chars/=3;
$subtime=60/$totaltime;
$result=$totaltime/$chars;
$result=$subtime/$result;
}
echo 'Your typing speed is: '.round($result,2).' words per minute.';
} else { unset($time); }
?>
<form method='post' style='margin:0px; padding:0px;'>
<input type='hidden' value='<? echo date('G-i-s-u'); ?>' name='timestart'>
<textarea name='typetext' style='width:50%; height:75px;'></textarea>
<input type='submit' value='submit'>
</form>
Note that the more you type the more accurate the test will be.
Also with the above script, the more you type the more accurate the test will be and you can type anything into the text box for the test.
cwarn23
Occupation: Genius
3,033 posts since Sep 2007
Reputation Points: 413
Solved Threads: 259