Click here to Skip to main content
14,700,155 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
char c;
printf("enter y for yes and n for no \n");
execute some statements

some statements
Updated 15-May-19 11:42am
Prerak Patel 17-Oct-11 8:02am
Not a question. Read some books, do Google and do it on your own.

You'll have to take input from user in JS prompt then do some thing like this in PHP

echo("Enter Y for yes and N for no")

if(//prompt value here == "Y")

php dose not have a console to enter user input it just work under server side web page
If you want to run php in the console has a simple solution that works from version 4 of php until today (my version is 7.2) that is the readline.
Unfortunately he needs the user to press enter after typing
$c = readline("Enter y for yes and n for no and press enter to confirm\n");
$c = strtolower($c);
if ($c == 'y' || $c == 'yes' ) {
    echo 'You chose yes' . PHP_EOL;
} else {
    echo 'You chose no [' . $c . ']' . PHP_EOL;
echo 'exiting program...' . PHP_EOL;

You can also use the stream_get_line function

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900