Ask Question Forum:
Model Library:2025-02-08:A.I. model is online auto reply
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by duncanb7
at 2024-04-25 04:39:52
Point:500 Replies:8 POST_ID:828484USER_ID:11059
Topic:
PHP Scripting Language;;JavaScript
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
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); }} 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:
Author: duncanb7 replied at 2024-04-29 07:34:04
Thanks for all of your reply
It seems no one interested in
fseek()
It seems no one interested in
fseek()
Assisted Solution
Expert: Ray Paseur replied at 2024-04-25 07:04:16
125 points GOOD
It's always a good idea to read the online man pages and especially the user-contributed notes. Lots of experts contribute to the PHP web site:
http://us3.php.net/manual/en/function.fseek.php#102994
http://us3.php.net/manual/en/function.fseek.php#102994
Author: duncanb7 replied at 2024-04-25 06:02:46
Thanks for your start and get more interested in php.
If others experts know more fseek() usage, please advise
Duncan
If others experts know more fseek() usage, please advise
Duncan
Assisted Solution
Expert: nepaluz replied at 2024-04-25 05:15:34
125 points GOOD
I wrote before reading your response.
The question was posted in PHP and the answer provided is also PHP. If you want a solution to fseek(), someone esle will probably have to step in.
The suggested code, as you say, solves your problem, and I have further refined / corrected it for you as there was a flaw (the resutant file would have contained ONLY the amended lines and NO others)
The question was posted in PHP and the answer provided is also PHP. If you want a solution to fseek(), someone esle will probably have to step in.
The suggested code, as you say, solves your problem, and I have further refined / corrected it for you as there was a flaw (the resutant file would have contained ONLY the amended lines and NO others)
Assisted Solution
Expert: nepaluz replied at 2024-04-25 05:10:23
125 points GOOD
you will have to change the code and put the implde line OUTSIDE the conditional test for the first item in the line.
$file = "javascript.csv";$proverbs = file($file);$num = count($proverbs);for ($c=0; $c < $num; ++$c) { $custom = array_shift($proverbs); $line_of_text = explode(',', $custom); if ($line_of_text[0] > 0) { echo $line_of_text[0].'<br></br>' ; $line_of_text[0] =1232222; } $proverbs[] = implode(",",$line_of_text);}file_put_contents($file, $proverbs); 1:2:3:4:5:6:7:8:9:10:11:12:13:
Author: duncanb7 replied at 2024-04-25 05:08:19
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
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
Author: duncanb7 replied at 2024-04-25 04:50:48
Thanks , I will look into it and try
Accepted Solution
Expert: nepaluz replied at 2024-04-25 04:50:03
125 points GOOD
use this, I just gave you a response on your other question:
$file = "javascript.csv";$proverbs = file($file);$num = count($proverbs);for ($c=0; $c < $num; ++$c) { $custom = array_shift($proverbs); $line_of_text = explode(',', $custom); if ($line_of_text[0] > 0) { echo $line_of_text[0].'<br></br>' ; $line_of_text[0] =1232222; $proverbs[] = implode(",",$line_of_text); }}file_put_contents($file, $proverbs); 1:2:3:4:5:6:7:8:9:10:11:12:13: