0
<?php
echo "Hello there. So I hear you're learning to be a PHP programmer!\n";
echo "Why don't you type in your name for me:\n";
$name = trim(fgets(STDIN));
echo "\nThanks, " . $name . ", it's really nice to meet you.\n\n";
?>

a am using php version 5.5.19 xampp

habibun
  • 1,552
  • 2
  • 14
  • 29
  • What is `STDIN`? a string, a constant? – Sean May 16 '15 at 05:32
  • [What does the PHP error message “Notice: Use of undefined constant” mean?](http://stackoverflow.com/questions/2941169/what-does-the-php-error-message-notice-use-of-undefined-constant-mean) – Sean May 16 '15 at 05:33
  • What is your question?? – Saty May 16 '15 at 05:36
  • 3
    Are you running that in a web mode? [STDIN](http://php.net/manual/en/features.commandline.io-streams.php) is a CLI specific constant. – Ulver May 16 '15 at 05:42
  • I think u should use define('STDIN',fopen("php://stdin","r")); in the at top of the php file. – user3419778 May 16 '15 at 06:17

2 Answers2

5

Assuming you are running from command line interface (CLI):

Define a STDIN constant at the top of your file:

define('STDIN', fopen('php://stdin', 'r'));

Or just replace STDIN constant with:

$name = trim(fgets(fopen('php://stdin', 'r')));
Vahid Hallaji
  • 7,159
  • 5
  • 42
  • 51
1
<?php

echo "Hello there. So I hear you're learning to be a PHP programmer!\n";

echo "Why don't you type in your name for me:\n";

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

$name=trim(fgets($stdin));

echo "\nThanks, " . $name . ", it's really nice to meet you.\n\n";

fclose($file);

?> 
Tamil Selvan C
  • 19,913
  • 12
  • 49
  • 70
Tal
  • 1,091
  • 12
  • 25