0

When I was searching for how to read a single character from the console, I found this article, but I don't think that this solution works for Windows. So my querstion is, how to accomplish a readline() for a single character that works without pressing enter/return after every single character?

I tried stream_get_line(STDIN, 1), but this function neither returns after I typing the first character nor returns only one character after pressing enter/return.

Community
  • 1
  • 1
Cubi73
  • 1,891
  • 3
  • 31
  • 52
  • So, to clarify, the difference between your question and the previous one is that you need a solution that works on Windows? Also, have you tried the solutions on that question, and verified (e.g. from error messages or manual notes) that they are failing *because you're on Windows*, and not for some other reason? – IMSoP Sep 28 '14 at 14:31
  • by the way : if you actually want to interact with the user in any other way than via HTTP data ... PHP is not your language - it was created for the sole purpose of WWW / HTTP. – specializt Sep 28 '14 at 14:34
  • I veryfied that the previous solution isn't working on Windows, because Windows "doesn't know the command stty". I don't want to interact with the user via http data, I run my PHP script in Windows's command line prompt. The previous solution is a solution for the missing `readline` library on Windows. But it doesn't work for reading a single character like C#'s `System.Console.ReadKey()`. – Cubi73 Sep 28 '14 at 14:40
  • @specializt With all due respect, that's a massive exaggeration. PHP has plenty of functions specifically aimed at CLI programming, and many more that have nothing to do with HTTP or terminal I/O. It is often extremely useful to be able to reuse code (not to mention experience) in multiple contexts, so its not always a case of picking the best possible CLI language. That said, the combination of Windows, PHP, and CLI is relatively unusual, so it's not surprising that this answer is relatively hard to come by. – IMSoP Sep 28 '14 at 15:34

0 Answers0