Tuesday, August 31, 2010

Word Repetition Count and Highlight

Intro
Ever wanted something to count all the repeated words and highlight each word with a different color? No? Well I did!

I looked around but didn't find what I wanted so I wrote my own. A quick & dirty PHP script. It was a good waste of those extra 3 hours I had.

Caveats
Script limitations/bugs:
  • All punctuation is removed
  • Some long words are not counted for some reason
  • The colors are random so some may not be pleasant
  • Sometimes it matches partial words sometimes it doesn't.
It's always good practice to sacrifice a Microsoftie before running/using the script, to make sure things run smooth. Depending on the kind of text, you may want to add Lawyers, Salesmen, Marketers and Apple Fanboys into the mix.

Script Types
I wrote 2 scripts: One for use for the command line (read from a text file and outputs to shell, which you could redirect to another file) and another for the web. You can modify the web one to make it check URLs directly, but I'm warning you: It'll massacre all kinds of styling and you'll need to do some extra work to make work properly.

Links
You can [ab]use the script here: http://sectorx.org/word-highlight-web.php

The scripts are available freely for download & redistribution as long as the credits are retained. If you make enhancements to the scripts, I'd appreciate it if you send them back to me to add them to the others (with your credits retained of course).

Demo
What better demo is than to test it on cats and geeks? :D

Yes, I cheated by manually placing the text in the middle for a better screenshot. Spank me for being bad.

No comments: