|
-
Jul 16th, 2006, 11:59 PM
#1
Thread Starter
Member
File system
Hi alll
I am handling large no file. I would like to read all those file content and would like to extract some line from file. Is there any body help me out. I would like to get code or some logic that i write code myself.
Thanks
Ramesh
-
Jul 17th, 2006, 03:33 AM
#2
Re: File system
Hi RameshChaudhary 
The principal is quite simple... you can read a whole file's contents like so:
PHP Code:
$fileContents = implode('', file('http://www.someplace.com/filename.xyz'));
This will assign the contents of the file too the variable $fileContents.
Optionally though you could just do this:
PHP Code:
$fileContents = file('http://www.someplace.com/filename.xyz');
That would generate an array, each element of the array representing one line of the file - you could loop through those to find the required lines and use them.
-- Ryan Jones
-
Jul 17th, 2006, 04:40 PM
#3
Member
Re: File system
This is a usefull bit. Thanks!
-
Jul 18th, 2006, 06:47 AM
#4
Thread Starter
Member
Re: File system
Thanks for your TIPs, Could you tell me how do i read specific line number or text on a file.
 Originally Posted by sciguyryan
Hi RameshChaudhary
The principal is quite simple... you can read a whole file's contents like so:
PHP Code:
$fileContents = implode('', file('http://www.someplace.com/filename.xyz'));
This will assign the contents of the file too the variable $fileContents.
Optionally though you could just do this:
PHP Code:
$fileContents = file('http://www.someplace.com/filename.xyz');
That would generate an array, each element of the array representing one line of the file - you could loop through those to find the required lines and use them.
-- Ryan Jones
-
Jul 18th, 2006, 06:59 AM
#5
Re: File system
Well each index in the array will correspond to the line number, such that:
PHP Code:
$fileContents = file('http://www.someplace.com/filename.xyz');
// line 1
$line1 = $fileContents[0];
// line 2
$line2 = $fileContents[1];
-
Jul 18th, 2006, 11:24 PM
#6
Thread Starter
Member
-
Jul 18th, 2006, 11:53 PM
#7
Re: File system
Unless you have any further questions please go to the "Thread Tools" menu above the first post and click "Mark Thread Resolved". This will let other forum users know your question has been answered. Thanks!
-
Jul 19th, 2006, 01:21 AM
#8
Thread Starter
Member
Re: File system
 Originally Posted by visualAd
Well each index in the array will correspond to the line number, such that:
PHP Code:
$fileContents = file('http://www.someplace.com/filename.xyz');
// line 1
$line1 = $fileContents[0];
// line 2
$line2 = $fileContents[1];
Hi VisualAD,
I have code below and it diplays contents of 'C:/zipunzip/unzip/prifiles/0006509972022089.pri' file. But i would like to view contetns of all files in 'C:/zipunzip/unzip/prifiles/
--------------------------------------------------------------------------
$lines = file('C:/zipunzip/unzip/prifiles/0006509972022089.pri');
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n";
}
echo "</br>";
// line 1
$line1 = $lines[0];
$line2 = $lines[1];
$line3 = $lines[2];
$line4 = $lines[3];
$line5 = $lines[4];
$line6 = $lines[5];
$line7 = $lines[6];
$line8 = $lines[7];
$line9 = $lines[8];
$line10 = $lines[9];
$line11 = $lines[10];
$line12 = $lines[11];
$line13 = $lines[12];
$line14 = $lines[13];
$line15 = $lines[14];
$line16 = $lines[15];
$line17 = $lines[16];
$line18 = $lines[17];
---------------------------------------------------------------------
Thanks
Ramesh
-
Jul 19th, 2006, 01:31 AM
#9
Re: File system
What on earth are you trying to do here?
Code:
$line1 = $lines[0];
$line2 = $lines[1];
$line3 = $lines[2];
$line4 = $lines[3];
$line5 = $lines[4];
$line6 = $lines[5];
$line7 = $lines[6];
$line8 = $lines[7];
$line9 = $lines[8];
$line10 = $lines[9];
$line11 = $lines[10];
$line12 = $lines[11];
$line13 = $lines[12];
$line14 = $lines[13];
$line15 = $lines[14];
$line16 = $lines[15];
$line17 = $lines[16];
$line18 = $lines[17];

You need to use opendir() and readdir() to find all the files in a given directory.
-
Jul 19th, 2006, 01:31 AM
#10
Re: File system
z0mg. Don't copy them all to separate variables like that, it's pointless 
If you want to view contents of all files in a folder you will have to loop through the files one by one and you can do that using scandir(). If you are using PHP 4 the alternative method of getting the filenames are also shown on the page a bit further down.
-
Jul 19th, 2006, 02:08 AM
#11
Thread Starter
Member
-
Jul 19th, 2006, 11:36 PM
#12
Thread Starter
Member
Re: File system
I would like loop contents of all files of directroy.
-
Jul 20th, 2006, 12:26 AM
#13
-
Jul 20th, 2006, 02:49 PM
#14
<?="Moderator"?>
Re: File system
Take a look at the PHP manual for the functions that allow you to manipulate directories.
http://uk2.php.net/manual/en/ref.dir.php
-
Jul 21st, 2006, 04:54 AM
#15
Thread Starter
Member
Re: File system
 Originally Posted by visualAd
That's nice for you.
could you tell me that how can i search string in a file.
-
Jul 21st, 2006, 06:41 AM
#16
Fanatic Member
Re: File system
 Originally Posted by RameshChaudhary
could you tell me that how can i search string in a file.
since you have your file read into an array $fileContents, simply loop through the array and check for your string.
ex.
PHP Code:
$search_string = "my string within quotes";
for($i=0;$i<=sizeof($fileContents);$i++){
//define your search term variable
$search_term = $fileContents[$i];
//check to see if this is your search string
if($search_term == $search_string){
// do your stuff
}
}
i hope this helps
Last edited by modpluz; Jul 21st, 2006 at 06:47 AM.
-
Jul 23rd, 2006, 01:28 AM
#17
Thread Starter
Member
Re: File system
Thanks, modpluz
I have large number of files (*.j31) in directory. I would like to rename all files in 5099709047725.jpg. The file name comes after data processing. Want some logic to rename all files in a directory
thanks
Last edited by RameshChaudhary; Jul 23rd, 2006 at 04:12 AM.
-
Jul 23rd, 2006, 07:50 AM
#18
<?="Moderator"?>
Re: File system
You need to copy the file using copy() and then delete it using unlink().
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|