We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

fseek() is not working in my PHP5.2.16 Linux

duncanb7
duncanb7 asked
on
Medium Priority
1,014 Views
Last Modified: 2012-05-11
Dear Experts,
I get one simple example csv file such as
1,2,3  
4,5,6
7,8,9
Total 10 bytes for each row
And I write php file and if every line's first cell is > 0 then overwrite the same cell value by 0 , So
if php pass, the output should like this
0,2,3
0,5,6
0,8,9

So I used fopen with "r+" option because read and write within the same file
and use fseek() with negative offset to backward file pointer to the previous row
since every row is just 10 byte and I used -10 in fseek() and Ftell() is also report correct file pointer
But the question fseek()  could not  locate the exact file pointer by the system with the
Warning: fseek() [function.fseek]: stream does not support seeking in www.mydomain.data.php on line

So the output is same as before, so fseek is fail in my php data.php and I also try
rewind() that is also NO any response.

SO anyone know what is the warning meaning ? and I check a lot thing at
http://hk.php.net/manual/en/book.stream.php and
see the stream data method at  http://hk.php.net/manual/en/book.stream.php

write a simple data into csv file why it is so difficult. Please advise.

Duncan

/*******data.php****?

<?php
/*phpinfo();*/
$file_handle = fopen("javascript.csv", "r+");
while (!feof($file_handle) ) {
echo ftell($file_handle);
echo '<br></br>';
$line_of_text = fgetcsv($file_handle, 10);
echo '<br></br>';

if ($line_of_text[0] >0 ) {
echo $line_of_text[0].'<br></br>' ;
fseek($file_handle, -10, SEEK_SET);
$line_of_text[0] =0;
fwrite($file_handle, $line_of_text);
   }
}

Open in new window

Comment
Watch Question

Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks , I will look into it and try

Author

Commented:
it work for fine if we use file() and array_shift instead of fseek() but this thread is more
concentration on fseek() to achieve the goal if we could use it.
 
Or could we tell when and why we use fseek() and arry_shift() ?

Please advise

Dunca
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks for your start and  get more interested in php.

If others experts know more fseek() usage, please advise

Duncan
Most Valuable Expert 2011
Author of the Year 2014
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks for all of your reply
It seems no one interested in
fseek()
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.