Home > Code Snippets, PHP > User input in php command line

User input in php command line

January 17th, 2007

Ever wondered how to capture the user input when writing php command line scripts ?

<?php
 
function getInput($msg){
  
fwrite(STDOUT"$msg: ");
  
$varin trim(fgets(STDIN));
  return 
$varin;
}
 
?>

The function above is being used by me in certain command line scripts, where I need user responses.

  • Share/Bookmark

Code Snippets, PHP , ,

  1. ryan
    October 29th, 2011 at 00:18 | #1

    thank you..

  1. No trackbacks yet.