Well, good question indeed.
Telnet seems to be so simple, yet it is not. There is a lot to keep track of. Personally I'd go with a regular client instead of coding your own. Via PHP (correction; web, unless you use Java), you cannot control cursor positions, ANSI colors etc. (Or, it'd be one H**L of a project).
If you're really serious about this, start by learning the telnet RFC. When you know this by head, drop me an e-mail.
http://www.freesoft.org/CIE/RFC/854/
There are, however, already Java telnet clients available. Try google if this is what you want.