09-25-2007, 07:57 PM
|
#1 (permalink)
|
|
The Contributor
Join Date: Sep 2007
Location: Finland
Posts: 45
Thanks: 3
|
Reading from txt file..
Hello.. This is my first question and just want to say before it that this is awesome forum!! Thanks for that..
Ok.. I need to read text file and every second line ONLY!?
Like this:
0
2
4
6
8
10
and so on..
I have here my script which will print all lines. If someone could look at it and maybe quide me how to modify this so it will print only every second line like I sayd before.
Code:
$filename = "postitoimi.txt";
$file = fopen($filename,"r");
$print = file("postitoimi.txt");
$lines = count($print);
$lines2 = $lines - 1;
$i = 0;
while ($i <= $lines2)
{
$patterns = array("(","'",")",",");
$replacements = array("","",""," ");
$data = str_replace($patterns, $replacements, $print[$i]);
$data = explode(",", $data);
print($data[0] . $data[1] . "<br />");
$i++;
}
Reason why I need to do this is that, in that textfile there is 2 information for every one ID number. And those are all inviditual lines. My customers old CMS is doing that now I need to convert that into my own CMS..
anyway, thanks for all help!
- Marxx
|
|
|