fputs
-
fputs — Alias of fwrite
In PHP,
fwriteandfputsare equivalent.PHP
$f = fopen('/path/to/foobar', 'w'); # identical fwrite($f, 'chars'); fputs($f, 'chars'); fclose($f);
Ruby’s
Fileobjects, and all Ruby objects that include theIOmixin, have instance methodswriteandputs. Unlike PHP, they are not equivalent.Ruby
File.open('/path/to/foobar', 'w') do |f| f.write("foo") # writes "foo" f.write("foo\n") # writes "foo\n" f.puts("foo") # writes "foo\n" f.puts("foo\n") # writes "foo\n" end
As shown by the example above, Ruby’s
File#writemethod does not append newlines. This is the familiar behavior from PHP’sfwriteandfputs.Ruby’s
File#putsmethod behaves differently. It will always append a newline to any line that does not already end in one.see also
Looking for Rails or PHP web application development, integration, and training?
Rails for PHP is brought to you by Maintainable Software. Get custom web applications and personalized training from the authors of the book and website.

