dsa456369 2017-12-19 12:22
浏览 231
已采纳

php中readline与fread / fgets的区别

I have always used readline in my console commands before, but today I've come across the fread and fgets functions and my question is: what is the difference in using these two approaches:

// first
$inputLine = readline();

// second
$inputLine = fgets(STDIN);

they both do pretty much the same, do they not?

  • 写回答

1条回答 默认 最新

  • dongliang1893 2017-12-20 04:54
    关注

    The only possible difference I can think of is just that readline() takes no arguments and can only read input from STDIN by default, whilst fgets() can take any resource to read from. So, in other words readline() is a synonym to fgets with the first predefined argument, like, for instance, fprintf() and printf().

    Consider the following:

    fprintf(STDOUT, "hello!");
    printf("hello!);
    

    This is quite common in php standard library.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部