Zend Certified Engineer

phpguru.org

Free PHP, Javascript and C# code

PHP Console Class


8th January 2006, 871 views

Just added a new class called Console, which wraps up some common Console script related functionality. All the methods are static, and it's PHP5 only. Methods include:

  • Console::Pause()
    Pauses exeution until the Enter/Return key is pressed.
  • Console::BooleanQuestion()
    Pass it a string (the question) and it will print the string, and wait for a Yes/No style answer from the user. It accepts yes/y/1/true for yes, and n/no/0/false for no (case independent). The result is returned as a boolean.
  • Console::ClearScreen()
    This one is Linux (and possibly bash?) specific. It sends the clear screen command code (ESCcm).
  • Console::GetLine()
    Simply waits for a line of input from the user followed by Enter/Return. Default buffer is 8192 bytes.
  • Console::ShowMenu()
    This really useful method shows a menu of items, and prompts the user to pick one. It takes a two dimensional array of menu items. The best thing is that you can associate callbacks with each menu item, providing a nice way of writing menu driven console apps.

More docs are provided inline, and there's a test script in the download directory which shows how to build a simple configuration app.

Top 10 referrering pages

  1. http://cl.pocari.org/2006-01-09-3.html (11 referrals)
  2. http://www.google.de/search?hl=de&q=php+console&b... (8 referrals)
  3. http://www.google.de/search?q=php+console&ie=utf-... (4 referrals)
  4. http://www.google.com/search?hl=en&client=firefox... (2 referrals)
  5. http://www.google.co.in/search?hl=en&q=php+from+c... (2 referrals)
  6. http://www.google.es/search?hl=es&q=php+console&b... (2 referrals)
  7. http://www.google.co.uk/search?hl=en&q=php+consol... (2 referrals)
  8. http://www.google.com/search?q=php+console+input&... (2 referrals)
  9. http://www.google.com/search?hl=en&q=php+console&... (2 referrals)
  10. http://www.google.ca/search?q=php+console&ie=utf-... (2 referrals)
- +
Rate this article

Link to me

If you use any of the code on this site (and if you don't I guess) or it makes your life easier, I'd appreciate a link - http://www.phpguru.org. Thanks!

RSS Feed for Comments

Comments

Author: Greg Beaver
Posted: 8th January 2006 21:42
for Console::ClearScreen(), you could also implement that as sending screensize LFs, which would work on windows. The user could control this by an option to the constructor.

Also, if there is an ANSI code for clearscreen, that would work on windows.
Quote

Post Comment

Your name:
Your email:
(Don't worry, I won't spam you. Also, if you do put your email address in here, you'll get notified of new comments. If you don't, you won't.)
Comments:
  Do not post support type questions please

 
CAPTCHA image If you can't read the CAPTCHA then press the submit button to get another. Your comment will re-appear (as if by magic...).
Captcha image