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?
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.