문제

Is there any way I can take input from user while running a PHP script via Command line interface?

올바른 솔루션이 없습니다

다른 팁

Waits for a return (newline):

$handle = fopen ('php://stdin', 'r');
$input  = fgets($handle);

For a single character such as a menu choice:

$input  = fgetc($handle);

just type

$line = fgets(STDIN);

example :

<?php
echo "What's your name ? ";
$line = fgets(STDIN);
echo "hi $line";

in your console :

php demo.php
What's your name ? Arrobe
hi Arrobe

fgets open a file in read mode

STDIN (for Standard Input) in a special file : your keyboard

source : https://www.php.net/manual/en/features.commandline.io-streams.php

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top