philip Thu Oct 17 22:59:42 2002 EDT Modified files: /phpdoc/en/reference/filesystem/functions fwrite.xml Log: Added a well commented example. Index: phpdoc/en/reference/filesystem/functions/fwrite.xml diff -u phpdoc/en/reference/filesystem/functions/fwrite.xml:1.2 phpdoc/en/reference/filesystem/functions/fwrite.xml:1.3 --- phpdoc/en/reference/filesystem/functions/fwrite.xml:1.2 Wed Apr 17 02:38:08 2002 +++ phpdoc/en/reference/filesystem/functions/fwrite.xml Thu Oct 17 22:59:42 2002 @@ -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
-- PHP Documentation Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php