mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 08:58:56 +00:00
Added a well commented example.
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@100096 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
4684dff065
commit
3bdad6c640
1 changed files with 39 additions and 1 deletions
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.2 $ -->
|
||||
<!-- $Revision: 1.3 $ -->
|
||||
<!-- splitted from ./en/functions/filesystem.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.fwrite">
|
||||
<refnamediv>
|
||||
|
@ -41,6 +41,44 @@
|
|||
<function>fopen</function> mode parameter.
|
||||
</para>
|
||||
</note>
|
||||
<para>
|
||||
<example>
|
||||
<title>A simple fwrite example</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$filename = 'test.txt';
|
||||
$somecontent = "Add this to the file\n";
|
||||
|
||||
// Let's make sure the file exists and is writable first.
|
||||
if (is_writable($filename)) {
|
||||
|
||||
// In our example we're opening $filename in append mode.
|
||||
// The file pointer is at the bottom of the file hence
|
||||
// that's where $somecontent will go when we fwrite() it.
|
||||
if (!$fp = fopen($filename, 'a')) {
|
||||
print "Cannot open file ($filename)";
|
||||
exit;
|
||||
}
|
||||
|
||||
// Write $somecontent to our opened file.
|
||||
if (!fwrite($fp, $somecontent)) {
|
||||
print "Cannot write to file ($filename)";
|
||||
exit;
|
||||
}
|
||||
|
||||
print "Success, wrote ($somecontent) to file ($filename)";
|
||||
|
||||
fclose($fp);
|
||||
|
||||
} else {
|
||||
print "The file $filename is not writable";
|
||||
}
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</para>
|
||||
<simpara>
|
||||
See also <function>fread</function>, <function>fopen</function>,
|
||||
<function>fsockopen</function>, <function>popen</function>, and
|
||||
|
|
Loading…
Reference in a new issue