alin19 Posted April 18, 2008 Share Posted April 18, 2008 how do i start reading a file from a specified bit? and find out the bit that i'm curently? a have a file that looks like this: php apache mysql michele alina john i what to start reading like this: x[0][0]="php"; x[0][1]="apache"; x[0][2]="mysql"; now find out what is the curent bit j=//curent bite; then start reading from j: x[1][0]="michele" x[1][1]="alina" x[1][2]="john" i=//curent bite Link to comment https://forums.phpfreaks.com/topic/101781-reading-from-file/ Share on other sites More sharing options...
alin19 Posted April 18, 2008 Author Share Posted April 18, 2008 <?php $file=fopen("C:\Documents and Settings\user\Desktop\php\\tickers.txt",'r'); if ($file) while (!feof($file)) { $order=fgets($file,999); echo $order; } ?> how do i open that file or start reading it from a specified place? Link to comment https://forums.phpfreaks.com/topic/101781-reading-from-file/#findComment-520777 Share on other sites More sharing options...
hitman6003 Posted April 18, 2008 Share Posted April 18, 2008 You can "seek" to a certain place in a file using fseek. http://www.php.net/fseek You can determine the current byte position using ftell. http://www.php.net/ftell However I think what you want is a combination of more common functions: // Read the entire file into an array, one line to an element $file = file("/path/to/file"); // loop through the lines foreach ($file as $line) { // split each line on one or more space characters ("\t", " ", etc) $data[] = preg_split('/\s+/', $line); } echo '<pre>' . print_r($data, true) . '</pre>'; Link to comment https://forums.phpfreaks.com/topic/101781-reading-from-file/#findComment-520829 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.