简体   繁体   中英

User input in PHP

Im new to PHP and I am trying to read user input in my code but im getting the error: Use of undefined constant STDIN - assumed 'STDIN'

<?php 
    echo "<h1>Armstrong number</h1>";
    echo "Enter number: ";

   fscanf(STDIN, "%d", $input); //Error Line

    $n=$input;
    $sum=0;
    while($n != 0)   
   {   
       $rem = $n % 10;   
       $sum = $sum + $rem*$rem*$rem;   
       $n = $n / 10;   

   } 
    if ($input == $sum) 
    echo $input." entered is an armstrong no.";
    else
    echo $input." isnt an armstrong no.";
?>
``

Because your conts "STDIN" isn't defined. For example, you can try this:

    $handle = fopen("your_file.txt", "r");
    
    define('STDIN', $handle);

and your code below

You are trying to check Armstrong number through browser.

Run your code through CLI.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM