|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2019-03-01 02:39 UTC] svnpenn at gmail dot com
Description:
------------
with PHP, several methods are available to produce output:
echo "hello world\n";
print "hello world\n";
print_r("hello world\n");
var_export("hello world\n");
However all these methods have something in common: they do not produce their
own newline. With each method, the user is required to provide a newline with
"\n", PHP_EOL or similar. This is bothersome because many other programming
languages offer such a method. For example Python:
print('hello world')
Perl:
use feature say;
say 'hello world';
Ruby:
puts 'hello world'
Lua:
print 'hello world'
Even C:
#include <stdio.h>
int main() {
puts("hello world");
}
Out of the above examples, I would say Perl and Ruby are most similar to PHP, in
that they also have the "print" method:
$ perl -e 'print 2; print 3;'
23
$ ruby -e 'print 2; print 3;'
23
However even in this case, "print" can be made to produce a newline by default:
$ perl -e '$\ = "\n"; print 2; print 3;'
2
3
$ ruby -e '$\ = "\n"; print 2; print 3;'
2
3
My request would be, in order of preference:
1. the "echo" method be modified such that it produces newline by default
2. new method method be added, perhaps "say", that produces newline by default
3. a variable be introduced, "$\" or similar, that controls output record
separator
I understand that some of these methods are decades old and unlikely to change,
but if I do nothing then I have only myself to blame.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 15:00:02 2025 UTC |
@spam2 you are a professional idiot. but as the page this bug is hosted on might exist for many years into future, i feel it my duty to give a proper refutation. results of the example you gave: echo $a, $b, $c; are well defined in other programming languages. Python will print the objects separated by "sep" (default empty) and finally by "end" (default newline): https://docs.python.org/library/functions#print Perl will print the objects separated by "$," (default empty) and finally by "$\" (default empty): https://perldoc.perl.org/functions/print.html Ruby will print the objects separated by "$," (default empty) and finally by "$\" (default empty): http://ruby-doc.org/core/Kernel.html#method-i-print And even Awk will print the objects separated by "OFS" (default space) and finally by "ORS" (default newline): http://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html#tag_20_06_13_10 As you have proven your poor understanding of programming languages (and the english language), i would strongly suggest that you simply stop posting. However i know this warning will fall on deaf ears. dumb has no off button.