【问题标题】:Use of undefined constant STDIN - assumed 'STDIN' [duplicate]使用未定义的常量 STDIN - 假定为“STDIN”[重复]
【发布时间】:2015-05-16 05:30:49
【问题描述】:
<?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";
?>

我正在使用 php 版本 5.5.19 xampp

【问题讨论】:

标签: php


【解决方案1】:

假设您从命令行界面 (CLI) 运行:

在文件顶部定义一个STDIN 常量:

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

或者只是将STDIN 常量替换为:

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

【讨论】:

    【解决方案2】:
    <?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);
    
    ?> 
    

    【讨论】:

    • 感谢这段代码在 cmd 中运行良好。
    猜你喜欢
    • 1970-01-01
    • 2014-02-06
    • 1970-01-01
    • 2020-10-15
    • 2017-12-19
    • 2018-08-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多