REWIND(3) 1 REWIND(3)rewind - Rewind the position of a file pointerSYNOPSIS
bool rewind (resource $handle)
DESCRIPTION
Sets the file position indicator for $handle to the beginning of the file stream.
Note
If you have opened the file in append ("a" or "a+") mode, any data you write to the file will always be appended, regardless of the
file position.
PARAMETERS
o $handle
- The file pointer must be valid, and must point to a file successfully opened by fopen(3).
RETURN VALUES
Returns TRUE on success or FALSE on failure.
EXAMPLES
Example #1
rewind(3) overwriting example
<?php
$handle = fopen('output.txt', 'r+');
fwrite($handle, 'Really long sentence.');
rewind($handle);
fwrite($handle, 'Foo');
rewind($handle);
echo fread($handle, filesize('output.txt'));
fclose($handle);
?>
The above example will output something similar to:
Foolly long sentence.
SEE ALSO fread(3), fseek(3), ftell(3), fwrite(3).
PHP Documentation Group REWIND(3)
Check Out this Related Man Page
FSEEK(3) 1 FSEEK(3)fseek - Seeks on a file pointerSYNOPSIS
int fseek (resource $handle, int $offset, [int $whence = SEEK_SET])
DESCRIPTION
Sets the file position indicator for the file referenced by $handle. The new position, measured in bytes from the beginning of the file,
is obtained by adding $offset to the position specified by $whence.
In general, it is allowed to seek past the end-of-file; if data is then written, reads in any unwritten region between the end-of-file and
the sought position will yield bytes with value 0. However, certain streams may not support this behavior, especially when they have an
underlying fixed size storage.
PARAMETERS
o $handle
-A file system pointer resource that is typically created using fopen(3).
o $offset
- The offset. To move to a position before the end-of-file, you need to pass a negative value in $offset and set $whence to
SEEK_END.
o $whence
-$whence values are:
o SEEK_SET - Set position equal to $offset bytes.
o SEEK_CUR - Set position to current location plus $offset.
o SEEK_END - Set position to end-of-file plus $offset.
RETURN VALUES
Upon success, returns 0; otherwise, returns -1.
EXAMPLES
Example #1
fseek(3) example
<?php
$fp = fopen('somefile.txt', 'r');
// read some data
$data = fgets($fp, 4096);
// move back to the beginning of the file
// same as rewind($fp);
fseek($fp, 0);
?>
NOTES
Note
If you have opened the file in append ( a or a+) mode, any data you write to the file will always be appended, regardless of the
file position, and the result of calling fseek(3) will be undefined.
Note
Not all streams support seeking. For those that do not support seeking, forward seeking from the current position is accomplished
by reading and discarding data; other forms of seeking will fail.
SEE ALSO ftell(3), rewind(3).
PHP Documentation Group FSEEK(3)
Can you grep for a sentence. I have to search logs everyday at work and I was wondering if I could search for a string of words instead of just one.
for example, if I had to find this sentence:
"Received HTTP message type"
How would I grep it (2 Replies)
I'm not sure if this is the place to ask this question but I have a script on an IBM RS6000 that has quit working. I can manually run a backup using SMIT and it appears okay, but not sure about the script.
----------code------------
#!/bin/ksh
#set -x
echo backup beginning
date
find... (7 Replies)
hi everybody!
i need to read a specific line from a text file using C. can any one suggest how to do it.
i m aware abt fread(), fwrite(), fseek()... but using these allows the pointer to be moved 1 character at a time. Is there a way i could jump directly to a line if i know the line number?... (4 Replies)
Hello Friends,
I got stuck with fgets () & rewind() function .. Please need help..
Actually I am doing a like,
The function should read lines from a txt file until the function is called..
If the data from the txt file ends then it goes to the top and then again when the function is called... (1 Reply)
Hi All,
We append the output of a file's size in a file. But a newline character is appended after the variable.
Pls help how to clear this.
filesize=`ls -l test.txt | awk `{print $5}'`
echo File size of test.txt is $filesize bytes >> logfile.txt
The output we got is,
File size of... (4 Replies)
what is the difference between
fopen and open
fread and read
fwrite and write
open and create
why this much of functions for the i/o when everything does the same...?
What is their major difference?
In which case, which is the best to use.
:confused:'ed Collins (2 Replies)
Hello All ,
i am a newbie in korn shell scripting trying to trim a sentence that is parsed into a variable . The format of the sentence has three words that are separated from other by a
" : " colon and "." period . Format of the sentence looks like
... (5 Replies)
Hi,
There's a long sentence from which I need to extract only the part which is at the right side of the word LENGTH i.e. 15
long sentence :
<INPUT VAR1 ="" DATATYPE ="number(p,s)" VAR2 ="" VAR3 ="3" VAR4="0" VAR5 ="ELEMITEM" VAR6 ="NO" VAR7 ="NOT A KEY" VAR8 ="17" LEVEL ="0" NAME... (3 Replies)
Hi,
now i need to remove the entires i inserted into my .txt file.
echo -n "Title: "
read Title
echo -n "Author: "
read Author
if grep -q "$Title: $Author" "BookDB.txt"; then
sed '$Title: $Author' BookDB.txt
echo "Book Title '$Title' removed successfully!"
... (6 Replies)
I have one input file and content of file is :
---------------------------------------------------
Input.txt
---------------------------------------------------
american express
Bahnbau GmbH
Bahnbau GmbH
CRH Europe
crh europe
Helgeland Ferdigbetong AS... (8 Replies)
Hi,
I want to know how to redirect the output of topas -P to a file in a readable format. I tried doing it by using
topas -P > topas.txt but the output is not properly aligned and when I opened it using vi it ahd some characters.
Please help me out in this.
Thanks (1 Reply)