File: README.md

package info (click to toggle)
php-cli-prompt 1.0.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 104 kB
  • ctags: 21
  • sloc: php: 64; makefile: 6
file content (56 lines) | stat: -rw-r--r-- 1,386 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
CLI-Prompt
==========

While prompting for user input using `fgets()` is quite easy, sometimes you
need to prompt for sensitive information. In these cases, the characters typed
in by the user should not be directly visible, and this is quite a pain to
do in a cross-platform way.

This tiny package fixes just that for you:

```php
<?php

echo 'Say hello: ';

$answer = Seld\CliPrompt\CliPrompt::hiddenPrompt();

echo 'You answered: '.$answer . PHP_EOL;

// Output in the CLI:
// 
// Say hello:
// You answered: hello
```

API
---

- `Seld\CliPrompt\CliPrompt::hiddenPrompt($allowFallback = false);`

  > Prompts the user for input and hides what they type. If this fails for any
  > reason and `$allowFallback` is set to `true` the prompt will be done using
  > the usual `fgets()` and characters will be visible.

- `Seld\CliPrompt\CliPrompt::prompt();`

  > Regular user prompt for input with characters being shown on screen.

In both cases, the trailing newline the user enters when submitting the answer
is trimmed.

Requirements
------------

PHP 5.3 and above

License
-------

CLI-Prompt is licensed under the MIT License - see the LICENSE file for details

Acknowledgments
---------------

- This project uses hiddeninput.exe to prompt for passwords on Windows, sources
  and details can be found on the [github page of the project](https://github.com/Seldaek/hidden-input).