We Recommend

Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems
Wicked Cool PHP contains a wide variety of scripts to process credit cards, check the validity of email addresses, template HTML, and serve dynamic images and text.


Posted By

jachin on 10/04/08


Tagged

print console commandline prompt stdin flush confirmation


Versions (?)


PHP Command Line Confirmation Prompt


Published in: PHP 


A basic confirmation question and test.

  1. $message = "Are you sure you want to do this [y/N]";
  2. print $message;
  3. $confirmation = trim( fgets( STDIN ) );
  4. if ( $confirmation !== 'y' ) {
  5. // The user did not say 'y'.
  6. exit (0);
  7. }

Report this snippet 

You need to login to post a comment.