cvs: phpdoc-zh /reference/filesystem/functions fwrite.xml

From: Date: Sat, 08 Feb 2003 03:15:52 +0000
Subject: cvs: phpdoc-zh /reference/filesystem/functions fwrite.xml
Groups: php.doc.zh 
Request: Send a blank email to doc-zh+get-1019@lists.php.net to get a copy of this message
lm92 Fri Feb 7 22:15:52 2003 EDT Modified files: /phpdoc-zh/reference/filesystem/functions fwrite.xml Log: finish Index: phpdoc-zh/reference/filesystem/functions/fwrite.xml diff -u phpdoc-zh/reference/filesystem/functions/fwrite.xml:1.1 phpdoc-zh/reference/filesystem/functions/fwrite.xml:1.2 --- phpdoc-zh/reference/filesystem/functions/fwrite.xml:1.1 Sun Sep 29 22:56:19 2002 +++ phpdoc-zh/reference/filesystem/functions/fwrite.xml Fri Feb 7 22:15:52 2003 @@ -1,31 +1,27 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> <!-- splitted from ./en/functions/filesystem.xml, last change in rev 1.2 --> <refentry id="function.fwrite"> <refnamediv> <refname>fwrite</refname> - <refpurpose>Binary-safe file write</refpurpose> + <refpurpose>ÒÔ¶þ½øÖÆ·½Ê½Ð´ÈëÎļþ</refpurpose> </refnamediv> <refsect1> - <title>Description</title> + <title>ÃèÊö</title> <methodsynopsis> <type>int</type><methodname>fwrite</methodname> - <methodparam><type>int</type><parameter>fp</parameter></methodparam> + <methodparam><type>resource</type><parameter>handle</parameter></methodparam> <methodparam><type>string</type><parameter>string</parameter></methodparam> <methodparam choice="opt"><type>int</type><parameter>length</parameter></methodparam> </methodsynopsis> <simpara> - <function>fwrite</function> writes the contents of - <parameter>string</parameter> to the file stream pointed to by - <parameter>fp</parameter>. If the <parameter>length</parameter> - argument is given, writing will stop after - <parameter>length</parameter> bytes have been written or the end - of <parameter>string</parameter> is reached, whichever comes - first. + <function>fwrite</function> °Ñ <parameter>string</parameter> µÄÄÚÈÝдÈë + ÎļþÖ¸Õë <parameter>handle</parameter> ´¦¡£ Èç¹ûÖ¸¶¨ÁË <parameter>length</parameter> £¬ + µ±Ð´ÈëÁË <parameter>length</parameter> ¸ö×Ö½Ú»òÕßдÍêÁË <parameter>string</parameter> + ÒÔºó£¬Ð´Èë¾Í»áÍ£Ö¹¡£ </simpara> <simpara> - <function>fwrite</function> returns the number of bytes - written, or -1 on error. + <function>fwrite</function> ·µ»ØÐ´ÈëµÄ×Ö·ûÊý£¬³öÏÖ´íÎóʱÔò·µ»Ø &false; ¡£ </simpara> <simpara> Note that if the <parameter>length</parameter> argument is given, @@ -36,13 +32,50 @@ </simpara> <note> <para> - On systems which differentiate between binary and text files - (i.e. Windows) the file must be opened with 'b' included in - <function>fopen</function> mode parameter. + ÔÚÇø»á¶þ½øÖÆÎļþ»òÎı¾ÎļþµÄϵͳ£¨Èç Windows£©ÉÏ£¬ + ´ò¿ªÎļþʱ±ØÐëÔÚ <function>fopen</function> µÄ´ò¿ªÄ£Ê½ÉÏÌí¼Ó¡®b¡¯¡£ </para> </note> + <para> + <example> + <title>Ò»¸ö¼òµ¥µÄfwrite·¶Àý</title> + <programlisting role="php"> +<![CDATA[ +<?php +$filename = 'test.txt'; +$somecontent = "Ìí¼ÓÕâЩÎÄ×Öµ½Îļþ\n"; + +// Ê×ÏÈÎÒÃÇҪȷ¶¨Îļþ´æÔÚ²¢ÇÒ¿Éд¡£ +if (is_writable($filename)) { + + // ÔÚÕâ¸öÀý×ÓÀÎÒÃǽ«Ê¹ÓÃÌí¼Óģʽ´ò¿ª$filename£¬ + // Òò´Ë£¬ÎļþÖ¸Õ뽫»áÔÚÎļþµÄ¿ªÍ·£¬ + // ÄǾÍÊǵ±ÎÒÃÇʹÓÃfwrite()µÄʱºò£¬$somecontent½«ÒªÐ´ÈëµÄµØ·½¡£ + if (!$handle = fopen($filename, 'a')) { + print "²»ÄÜ´ò¿ªÎļþ $filename"; + exit; + } + + // ½«$somecontentдÈëµ½ÎÒÃÇ´ò¿ªµÄÎļþÖС£ + if (!fwrite($handle, $somecontent)) { + print "²»ÄÜдÈëµ½Îļþ $filename"; + exit; + } + + print "³É¹¦µØ½« $somecontent дÈëµ½Îļþ$filename"; + + fclose($handle); + +} else { + print "Îļþ $filename ²»¿Éд"; +} +?> +]]> + </programlisting> + </example> + </para> <simpara> - See also <function>fread</function>, <function>fopen</function>, + ²Î¼û <function>fread</function>, <function>fopen</function>, <function>fsockopen</function>, <function>popen</function>, and <function>fputs</function>. </simpara>

« previous php.doc.zh (#1019) next »