PHP » PYTHON |
login |
register |
about
|
PYTHON file_put_contents
is this article helpful?
|
Python replacement for PHP's file_put_contents
[
edit
| history
]
# Python 2.5 and above: with open(filename, 'w') as f: f.write(data) # All versions of Python: f = open(filename, 'w') f.write(data) f.close() file_put_contents(PHP 5) file_put_contents — Write a string to a file DescriptionThis function is identical to calling fopen(), fwrite() and fclose() successively to write data to a file. If filename does not exist, the file is created. Otherwise, the existing file is overwritten, unless the FILE_APPEND flags is set. Parameters
Return ValuesThe function returns the number of bytes that were written to the file, or FALSE on failure. Examples
Example #1 Simple usage example
<?php
Example #2 Using flags
<?php
Example #3 Using stream contexts
<?php
Changelog
Notes
Tip
A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename and List of Supported Protocols/Wrappers for a list of supported URL protocols. See Also
|
more
Recently updated
more
Most requested
more
Last requests
|