|
|
 |
fputs (PHP 3, PHP 4 ) fputs -- Scrive su un puntatore a file Descrizioneint fputs ( int fp, string str [, int length])
fputs() č un alias di
fwrite() del tutto identico. Nota che il parametro
length č opzionale e se non specificato verrā scritta
l'intera stringa.
User Contributed Notes fputs |
 |
bschuetz at affinity dot net
23-Dec-1998 02: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 at nedstat dot nl
16-Jun-1999 03: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.
|
|
d at niel dot fiser dot cz
19-Mar-2000 06:37 |
|
Regarding STDERR: use php://stderr (php3.0.13+) or /dev/stderr for
accessing stderr. Read more at the page about fopen.
|
|
Doug at Here dot Com
01-Jul-2000 12: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
|
|
|
|
yvan dot rivard at cesart dot com
17-Apr-2001 09:52 |
|
This might seem silly for experienced users, but this bugged me for about
two hours (searching and trying to debug the damn thing).
If
you're on a Windows system doing tests on a Linux/Apache setup, and you're
writing stuff to a text file (then load that file to see if your content
is being written properly) and you realize only your first string is in
there, your problem is not your Windows, not Linux and not Apache. It's
probably Samba (the thing that makes it possible for your Linux and
Windows boxes to talk to each other) that's caching your file... Try
viewing your file via telnet or simply copy your file then read that
copy.
You can see content is being written to your file anyway,
because even though you don't see your new content (using notepad for
example), you do see your filesize increasing as you add more text to your
file.
|
|
mb at brenden dot com
25-Oct-2001 08:47 |
|
re prev msg about samba file cache -- samba parm to disable on share is
"oplocks"
|
|
Indigosock at hotmail dot com
18-Jul-2002 12:23 |
|
im trying to write to a file called affiliate.txt, instead its writing to
affiliatetxt ... i checked the script and all the dots are there do i need
to put some special thing in there? this is what m
doing: $string="hello"; $fp=
fopen(affiliate.txt,"aw"); fputs($fp, $string);
fclose($fp); also for people who dont know much about php like me
you can't just go fputs(what you want to save); you need to open the file
from with in fputs (i used $fp and then write you data... it makes it
neater if you use a variable for this to then you need to close the $fp
any way i dont know much php im writing my first script
|
|
eutanasio at hotmail dot com
19-Jul-2002 05:01 |
|
You'd better put the name of the file (within fopen) into "" . If
you dont, php will understand the fullstop . as a string-linking
operator. Sorry because of my poor English.
|
|
 |
| |