★ wanayoo — archive 1999 http://www.php.net/manual/ja/function.fputs.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to ファイルシステム
Quick Reference
English version of this pageGerman version of this pageItalian version of this pageFrench version of this pageHungarian version of this page
ファイルシステム
* basename
* chgrp
* chmod
* chown
* clearstatcache
* copy
* delete
* dirname
* diskfreespace
* fclose
* feof
* fgetc
* fgetcsv
* fgets
* fgetss
* file
* file_exists
* fileatime
* filectime
* filegroup
* fileinode
* filemtime
* fileowner
* fileperms
* filesize
* filetype
* flock
* fopen
* fpassthru
* fputs
* fread
* fscanf
* fseek
* fstat
* ftell
* ftruncate
* fwrite
* set_file_buffer
* is_dir
* is_executable
* is_file
* is_link
* is_readable
* is_writeable
* link
* linkinfo
* mkdir
* pclose
* popen
* readfile
* readlink
* rename
* rewind
* rmdir
* stat
* lstat
* realpath
* symlink
* tempnam
* touch
* umask
* unlink
Manual: fputs
View the source code for this pageSearch the site



Previous page
 fpassthru
 Updated
Sat, 12 Aug 2000
fread 
Next page


fputs

(PHP3 , PHP4 )

fputs -- ファイルポインタに書き込む

説明

int fputs (int fp, string str [, int length])

fputs()fwrite() の別名で、すべての面で同一です。 length パラメータはオプションであり、 指定されない場合、文字列全体が書かれることに注意して下さい。


User Contributed Notes: fputs


bschuetz@affinity.net
22-Dec-1998 07:30
Length is required if you are writing out a lot of data. For instance, if you are base64 decoding an email attachment and writing it out to a file you have to specify the length if the file is over a certian size or else the binary data will be corrupt.

fputs($fp,$binary,strlen($binary));

Will yield the desired results.

When tested with a 1k the length wasn't required but with a larger file, around 27k it needs the length to work properly.



adam@nedstat.nl
16-Jun-1999 08:19
A note about including length: if you are writing binary data you should *always* specify the data's length. The reason is that the operating system has a special character to denote end of *strings*, but not for binary data. Binary data can be anything, so you can't very well reserve an end-of-data character. So the reason why writing binary data without specifying it's length can truncate it is that the only thing the system has to go on (without writing the entire contents of memory starting at the variable's address) is the end-of-string character, which could very well appear randomly in the middle of your set of binary data. The reason that length() could have worked on the variable is that it is implemented in C as sizeof(), which actually fetches the size of the memory chunk associated with the variable, but this is not advisable because sizeof() can also return the size of the *pointer* to the variable if you're not careful (ie, passing it by reference into a second function). In C it's best to keep track of size of the data you are accumulating as you accumlate it, so probably in PHP, too.


danbeck@scott.net
29-Jun-1999 12:25
If you are writing binary data you should only use fwrite()... this fuction doesn't work well if you mean to actually write binary data and not ASCII data.


d@niel.fiser.cz
19-Mar-2000 11:37
Regarding STDERR: use php://stderr (php3.0.13+) or /dev/stderr for accessing stderr. Read more at the page about fopen.


Doug@Here.Com
30-Jun-2000 05:46
The way I understand fputs (which is purported as an alias to fwrite which can be "Binary Safe")...
<pre>$fp = fopen("something.txt","w");
$string = "Hello World\\n"; // escape the slash from being magically
// being transformed into a newline
fwrite($fp, $string); // will proccess /n as newline ...
fwrite($fp, $string, strlen($string)); // will write the entire string to file without changing the '/n'
// into a single byte for newline on Unix-like machines or CR/LF on Win32 machines

</pre>

Hope this helps explain the definition of "could be Binary Safe". This is the reason why you must specify the length!

--Doug



flin@usa.com
28-Jul-2000 04:43
Re:escaping slashed (\) data. The problem with using a:

fwrite($fd, stripslashes($string))

approach is that you can no longer use the \ sign in a script. So if you have \", the \ sign will be stipped in the saved text.



ozgur@istanbulnet.com.tr
02-Aug-2000 03:13
i wonder if i can use something like :
$filepointer = fopen ("/path/to/the/file/to/be/accessed.txt", "w");
print $filepointer <<ENDOFDATA;
Username = $username_var
$Password = $pasword_var
.
.
.
etc..
ENDOFDATA
fclose($filepointer);

a little Perlish thing but i dont know if that works, i'll try it now ;=)



 About Notes


Previous page
 fpassthru
 Updated
Sat, 12 Aug 2000
fread 
Next page





Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.