| | |
Can I get a simple php code to measure how many words per minute someone can type?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Mar 2009
Posts: 3
Reputation:
Solved Threads: 0
Can I get a simple php code to measure how many words per minute someone can type?
0
#1 Mar 20th, 2009
Re: Can I get a simple php code to measure how many words per minute someone can type?
0
#2 Mar 20th, 2009
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
Re: Can I get a simple php code to measure how many words per minute someone can type?
0
#3 Mar 20th, 2009
Yes you can get , I guess next question would be how to make it work ?
Re: Can I get a simple php code to measure how many words per minute someone can type?
0
#4 Mar 20th, 2009
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.
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.
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Re: Can I get a simple php code to measure how many words per minute someone can type?
0
#5 Mar 20th, 2009
Re: Can I get a simple php code to measure how many words per minute someone can type?
0
#6 Mar 21st, 2009
•
•
•
•
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?
php Syntax (Toggle Plain Text)
<? 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.<br>'; 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.<br>'; } 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><br> Note that the more you type the more accurate the test will be.
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Re: Can I get a simple php code to measure how many words per minute someone can type?
0
#7 Mar 22nd, 2009
PHP would not be the best way to do this, not only due to the fact that page load times need to be taken into consideration (as already mentioned) but also because alot of the typing speed tests also take into account accuracy of the words typed. The code by cwarn23 above will count how many characters/words have been typed into a textbox and how long it took (roughly) but this would not stop you typing gibberish or 'a a a a a a a '....etc into the box.
You would really need something client-side (JavaScript maybe if it must be a web app) and a preset paragraph(s) to be typed. The script would then need to analyze the text as it is typed to make sure the words are input correctly, and if they are not then to make this count against the user. While this could be done in PHP, it is not going to be the simplest or easiest solution.
This is not a matter of 'basic code'.
You would really need something client-side (JavaScript maybe if it must be a web app) and a preset paragraph(s) to be typed. The script would then need to analyze the text as it is typed to make sure the words are input correctly, and if they are not then to make this count against the user. While this could be done in PHP, it is not going to be the simplest or easiest solution.
This is not a matter of 'basic code'.
Last edited by Will Gresham; Mar 22nd, 2009 at 1:38 am.
AJAX is not a programming language, scripting language or any other sort of language.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
![]() |
Similar Threads
- Help with automatic update problem and more (Viruses, Spyware and other Nasties)
Other Threads in the PHP Forum
- Previous Thread: cant get button to work parse error any ideas?
- Next Thread: setcookie not setting cookie...
| Thread Tools | Search this Thread |
.htaccess alerts apache api archive array autocomplete beginner binary broken cakephp checkbox class cms code convert cron curl database dataentry date display duplicates dynamic echo email emptydisplayvalue error execute explodefunction file files firstoptioninphpdroplist folder form forms function functions google hack href htaccess html htmlspecialchars image include insert ip javasciptvalidation javascript joomla keywords limit link login mail matching menu methods mlm multiple mysql network object oop paypal pdf php problem query radio random recursion recursive redirect remote script search securephp server sessions shot sms source space sql subscription syntax system table tutorial tutorials update upload url validator variable video web youtube






