fwrite

  • To write data to a file in PHP, we call the fwrite function, passing it a stream resource and the data to write.

    PHP

    $f = fopen('/path/to/foobar', 'w');
    fwrite($f, 'chars');
    fclose($f);

    To write data to a file in Ruby, we first get a File instance and then call the File#write instance method.

    Ruby

    File.open('/path/to/foobar', 'w') do |f|
      f.write 'chars'
    end

    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.