Rasher's Toolbox

Back

keyb_prompt

mixed keyb_prompt(string prompt [, string default [, int max_input]]) -- Get input from stdin.

Description

Echoes a prompt with the text prompt and accepts one line (or 1024 or max_input bytes) of input from stdin. A default choice can be set with the optional second parameter.

Example

<?php
  $name 
keyb_prompt('Enter your name: ');
  echo 
'Your name is: ' $name;
?>

This will output:

Enter your name: Jonas
Your name is: Jonas

Source

Published under the terms of the BSD License

<?php
function keyb_prompt($prompt$default false$max=1024) {
    if (!isset(
$GLOBALS['stdin'])) {
        
$GLOBALS['stdin'] = fopen('php://stdin''r');
    }
    echo 
"$prompt";
    
$return fgets($GLOBALS['stdin'], $max);
    if (
$return == '') {
        return 
$default;
    }
    else {
        return 
$return;
    }
}

?>

Last updated: Sat Jun 14 20:02:44 CEST 2008

Valid XHTML 1.0! Valid HTML 3.2!