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
Printable View
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
Hi RameshChaudhary :)
The principal is quite simple... you can read a whole file's contents like so:
This will assign the contents of the file too the variable $fileContents.PHP Code:$fileContents = implode('', file('http://www.someplace.com/filename.xyz'));
Optionally though you could just do this:
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.PHP Code:$fileContents = file('http://www.someplace.com/filename.xyz');
-- Ryan Jones
This is a usefull bit. Thanks!
Thanks for your TIPs, Could you tell me how do i read specific line number or text on a file.
Quote:
Originally Posted by sciguyryan
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];
Thanks visualAd ,
Ramesh
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!
Hi VisualAD,Quote:
Originally Posted by 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
What on earth are you trying to do here?
:confused: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.
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.
thanks
I would like loop contents of all files of directroy.
That's nice for you.
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
could you tell me that how can i search string in a file. ;)Quote:
Originally Posted by visualAd
since you have your file read into an array $fileContents, simply loop through the array and check for your string.Quote:
Originally Posted by RameshChaudhary
ex.
i hope this helpsPHP 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
}
}
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